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
c86086a5
authored
Feb 06, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: check instance for concurrent activities
parent
9c3f8b1d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
circle/common/models.py
+1
-1
circle/vm/models/activity.py
+25
-1
No files found.
circle/common/models.py
View file @
c86086a5
...
...
@@ -27,7 +27,7 @@ def activitycontextimpl(act, on_abort=None, on_commit=None):
class
ActivityModel
(
TimeStampedModel
):
activity_code
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'activity code'
))
parent
=
ForeignKey
(
'self'
,
blank
=
True
,
null
=
True
)
parent
=
ForeignKey
(
'self'
,
blank
=
True
,
null
=
True
,
related_name
=
'children'
)
task_uuid
=
CharField
(
blank
=
True
,
max_length
=
50
,
null
=
True
,
unique
=
True
,
help_text
=
_
(
'Celery task unique identifier.'
),
verbose_name
=
_
(
'task_uuid'
))
...
...
circle/vm/models/activity.py
View file @
c86086a5
...
...
@@ -10,6 +10,18 @@ from common.models import ActivityModel, activitycontextimpl
logger
=
getLogger
(
__name__
)
class
ActivityInProgressError
(
Exception
):
def
__init__
(
self
,
activity
,
message
=
None
):
if
message
is
None
:
message
=
(
"Another activity is currently in progress: '
%
s'."
%
activity
.
activity_code
)
Exception
.
__init__
(
self
,
message
)
self
.
activity
=
activity
class
InstanceActivity
(
ActivityModel
):
instance
=
ForeignKey
(
'Instance'
,
related_name
=
'activity_log'
,
help_text
=
_
(
'Instance this activity works on.'
),
...
...
@@ -18,7 +30,7 @@ class InstanceActivity(ActivityModel):
class
Meta
:
app_label
=
'vm'
db_table
=
'vm_instanceactivity'
ordering
=
[
'-started'
,
'instance'
,
'-id'
]
ordering
=
[
'-
finished'
,
'-
started'
,
'instance'
,
'-id'
]
def
__unicode__
(
self
):
if
self
.
parent
:
...
...
@@ -50,12 +62,24 @@ class InstanceActivity(ActivityModel):
@contextmanager
def
sub_activity
(
self
,
code_suffix
,
task_uuid
=
None
):
# Check for concurrent activities
active_children
=
self
.
children
.
filter
(
finished__isnull
=
True
)
if
active_children
.
exists
():
raise
ActivityInProgressError
(
active_children
[
0
])
act
=
self
.
create_sub
(
code_suffix
,
task_uuid
)
return
activitycontextimpl
(
act
)
@contextmanager
def
instance_activity
(
code_suffix
,
instance
,
task_uuid
=
None
,
user
=
None
):
# Check for concurrent activities
active_activities
=
instance
.
activity_log
.
filter
(
finished__isnull
=
True
)
if
active_activities
.
exists
():
raise
ActivityInProgressError
(
active_activities
[
0
])
act
=
InstanceActivity
.
create
(
code_suffix
,
instance
,
task_uuid
,
user
)
return
activitycontextimpl
(
act
)
...
...
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