Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9406a057
authored
Feb 14, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: move concurrent activity checking to ctor methods
parent
054e4941
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
14 deletions
+14
-14
circle/vm/models/activity.py
+14
-14
No files found.
circle/vm/models/activity.py
View file @
9406a057
...
@@ -47,6 +47,11 @@ class InstanceActivity(ActivityModel):
...
@@ -47,6 +47,11 @@ class InstanceActivity(ActivityModel):
@classmethod
@classmethod
def
create
(
cls
,
code_suffix
,
instance
,
task_uuid
=
None
,
user
=
None
):
def
create
(
cls
,
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
=
cls
(
activity_code
=
'vm.Instance.'
+
code_suffix
,
act
=
cls
(
activity_code
=
'vm.Instance.'
+
code_suffix
,
instance
=
instance
,
parent
=
None
,
resultant_state
=
None
,
instance
=
instance
,
parent
=
None
,
resultant_state
=
None
,
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
user
)
started
=
timezone
.
now
(),
task_uuid
=
task_uuid
,
user
=
user
)
...
@@ -54,6 +59,11 @@ class InstanceActivity(ActivityModel):
...
@@ -54,6 +59,11 @@ class InstanceActivity(ActivityModel):
return
act
return
act
def
create_sub
(
self
,
code_suffix
,
task_uuid
=
None
):
def
create_sub
(
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
=
InstanceActivity
(
act
=
InstanceActivity
(
activity_code
=
self
.
activity_code
+
'.'
+
code_suffix
,
activity_code
=
self
.
activity_code
+
'.'
+
code_suffix
,
instance
=
self
.
instance
,
parent
=
self
,
resultant_state
=
None
,
instance
=
self
.
instance
,
parent
=
self
,
resultant_state
=
None
,
...
@@ -64,28 +74,18 @@ class InstanceActivity(ActivityModel):
...
@@ -64,28 +74,18 @@ class InstanceActivity(ActivityModel):
@contextmanager
@contextmanager
def
sub_activity
(
self
,
code_suffix
,
on_abort
=
None
,
on_commit
=
None
,
def
sub_activity
(
self
,
code_suffix
,
on_abort
=
None
,
on_commit
=
None
,
task_uuid
=
None
):
task_uuid
=
None
):
"""Create a transactional context for a nested instance activity.
# 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
)
act
=
self
.
create_sub
(
code_suffix
,
task_uuid
)
return
activitycontextimpl
(
act
,
on_abort
=
on_abort
,
on_commit
=
on_commit
)
return
activitycontextimpl
(
act
,
on_abort
=
on_abort
,
on_commit
=
on_commit
)
@contextmanager
@contextmanager
def
instance_activity
(
code_suffix
,
instance
,
on_abort
=
None
,
on_commit
=
None
,
def
instance_activity
(
code_suffix
,
instance
,
on_abort
=
None
,
on_commit
=
None
,
task_uuid
=
None
,
user
=
None
):
task_uuid
=
None
,
user
=
None
):
"""Create a transactional context for an instance activity.
# 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
)
act
=
InstanceActivity
.
create
(
code_suffix
,
instance
,
task_uuid
,
user
)
return
activitycontextimpl
(
act
,
on_abort
=
on_abort
,
on_commit
=
on_commit
)
return
activitycontextimpl
(
act
,
on_abort
=
on_abort
,
on_commit
=
on_commit
)
...
...
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