Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
88ba8e10
authored
Nov 18, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: refact Node.online boilerplate to remote_query
parent
550924ea
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
6 deletions
+18
-6
circle/vm/models.py
+18
-6
No files found.
circle/vm/models.py
View file @
88ba8e10
...
...
@@ -126,16 +126,28 @@ class Node(TimeStampedModel):
@property
@method_cache
(
10
,
5
)
def
online
(
self
):
r
=
vm_tasks
.
ping
.
apply_async
(
queue
=
self
.
get_remote_queue_name
(
'vm'
),
expires
=
3
)
try
:
return
r
.
get
(
timeout
=
2
)
except
TimeoutError
:
return
False
return
self
.
remote_query
(
vm_tasks
.
get_num_cores
,
timeout
=
1
,
default
=
False
)
def
get_remote_queue_name
(
self
,
queue_id
):
return
self
.
host
.
hostname
+
"."
+
queue_id
def
remote_query
(
self
,
task
,
timeout
=
2
,
raise_
=
False
,
default
=
None
):
"""Query the given task, and get the result.
If the result is not ready in timeout secs, return default value or
raise a TimeoutError."""
r
=
task
.
apply_async
(
queue
=
self
.
get_remote_queue_name
(
'vm'
),
expires
=
timeout
+
1
)
try
:
return
r
.
get
(
timeout
=
timeout
)
except
TimeoutError
:
if
raise_
:
raise
else
:
return
default
def
__unicode__
(
self
):
return
self
.
name
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment