Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6586d87e
authored
Apr 25, 2014
by
Dudás Ádám
Committed by
Őry Máté
Apr 28, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: make async operation tasks abortable
parent
f6a5980b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
circle/vm/operations.py
+5
-3
circle/vm/tasks/local_tasks.py
+11
-7
No files found.
circle/vm/operations.py
View file @
6586d87e
...
@@ -9,7 +9,9 @@ from django.utils.translation import ugettext_lazy as _
...
@@ -9,7 +9,9 @@ from django.utils.translation import ugettext_lazy as _
from
celery.exceptions
import
TimeLimitExceeded
from
celery.exceptions
import
TimeLimitExceeded
from
common.operations
import
Operation
,
register_operation
from
common.operations
import
Operation
,
register_operation
from
.tasks.local_tasks
import
async_instance_operation
,
async_node_operation
from
.tasks.local_tasks
import
(
abortable_async_instance_operation
,
abortable_async_node_operation
,
)
from
.models
import
(
from
.models
import
(
Instance
,
InstanceActivity
,
InstanceTemplate
,
Interface
,
Node
,
Instance
,
InstanceActivity
,
InstanceTemplate
,
Interface
,
Node
,
NodeActivity
,
NodeActivity
,
...
@@ -21,7 +23,7 @@ logger = getLogger(__name__)
...
@@ -21,7 +23,7 @@ logger = getLogger(__name__)
class
InstanceOperation
(
Operation
):
class
InstanceOperation
(
Operation
):
acl_level
=
'owner'
acl_level
=
'owner'
async_operation
=
async_instance_operation
async_operation
=
a
bortable_a
sync_instance_operation
host_cls
=
Instance
host_cls
=
Instance
def
__init__
(
self
,
instance
):
def
__init__
(
self
,
instance
):
...
@@ -440,7 +442,7 @@ register_operation(WakeUpOperation)
...
@@ -440,7 +442,7 @@ register_operation(WakeUpOperation)
class
NodeOperation
(
Operation
):
class
NodeOperation
(
Operation
):
async_operation
=
async_node_operation
async_operation
=
a
bortable_a
sync_node_operation
host_cls
=
Node
host_cls
=
Node
def
__init__
(
self
,
node
):
def
__init__
(
self
,
node
):
...
...
circle/vm/tasks/local_tasks.py
View file @
6586d87e
from
celery.contrib.abortable
import
AbortableTask
from
manager.mancelery
import
celery
from
manager.mancelery
import
celery
@celery.task
@celery.task
(
base
=
AbortableTask
,
bind
=
True
)
def
a
sync_instance_operation
(
operation_id
,
instance_pk
,
activity_pk
,
allargs
,
def
a
bortable_async_instance_operation
(
task
,
operation_id
,
instance_pk
,
auxargs
):
activity_pk
,
allargs
,
auxargs
):
from
vm.models
import
Instance
,
InstanceActivity
from
vm.models
import
Instance
,
InstanceActivity
instance
=
Instance
.
objects
.
get
(
pk
=
instance_pk
)
instance
=
Instance
.
objects
.
get
(
pk
=
instance_pk
)
operation
=
getattr
(
instance
,
operation_id
)
operation
=
getattr
(
instance
,
operation_id
)
activity
=
InstanceActivity
.
objects
.
get
(
pk
=
activity_pk
)
activity
=
InstanceActivity
.
objects
.
get
(
pk
=
activity_pk
)
# save async task UUID to activity
# save async task UUID to activity
activity
.
task_uuid
=
async_instance_operation
.
request
.
id
activity
.
task_uuid
=
task
.
request
.
id
activity
.
save
()
activity
.
save
()
allargs
[
'activity'
]
=
activity
allargs
[
'activity'
]
=
activity
allargs
[
'task'
]
=
task
return
operation
.
_exec_op
(
allargs
,
auxargs
)
return
operation
.
_exec_op
(
allargs
,
auxargs
)
@celery.task
@celery.task
(
base
=
AbortableTask
,
bind
=
True
)
def
async_node_operation
(
operation_id
,
node_pk
,
activity_pk
,
allargs
,
auxargs
):
def
abortable_async_node_operation
(
task
,
operation_id
,
node_pk
,
activity_pk
,
allargs
,
auxargs
):
from
vm.models
import
Node
,
NodeActivity
from
vm.models
import
Node
,
NodeActivity
node
=
Node
.
objects
.
get
(
pk
=
node_pk
)
node
=
Node
.
objects
.
get
(
pk
=
node_pk
)
operation
=
getattr
(
node
,
operation_id
)
operation
=
getattr
(
node
,
operation_id
)
activity
=
NodeActivity
.
objects
.
get
(
pk
=
activity_pk
)
activity
=
NodeActivity
.
objects
.
get
(
pk
=
activity_pk
)
# save async task UUID to activity
# save async task UUID to activity
activity
.
task_uuid
=
async_node_operation
.
request
.
id
activity
.
task_uuid
=
task
.
request
.
id
activity
.
save
()
activity
.
save
()
allargs
[
'activity'
]
=
activity
allargs
[
'activity'
]
=
activity
allargs
[
'task'
]
=
task
return
operation
.
_exec_op
(
allargs
,
auxargs
)
return
operation
.
_exec_op
(
allargs
,
auxargs
)
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