Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Commits
2801c10d
Commit
2801c10d
authored
3 years ago
by
Nathan Hertz
Committed by
Nathan Hertz
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Capability version state is now correctly set to Complete and Failed
when it is desired
parent
6c342cd4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
shared/workspaces/workspaces/capability/schema.py
+38
-7
38 additions, 7 deletions
shared/workspaces/workspaces/capability/schema.py
shared/workspaces/workspaces/capability/services/capability_service.py
+5
-5
5 additions, 5 deletions
...aces/workspaces/capability/services/capability_service.py
with
43 additions
and
12 deletions
shared/workspaces/workspaces/capability/schema.py
+
38
−
7
View file @
2801c10d
...
...
@@ -25,7 +25,7 @@ import json
import
logging
import
pathlib
import
re
from
typing
import
Dict
,
List
from
typing
import
Dict
,
List
,
Optional
import
pendulum
import
requests
...
...
@@ -239,15 +239,42 @@ class State(Base):
transition
.
actions
.
append
(
action
)
self
.
transitions
.
append
(
transition
)
def
signal
(
self
,
message
:
Dict
,
execution
:
CapabilityExecutionIF
,
manager
:
ExecutionManagerIF
)
->
State
:
def
find_matching_transition
(
self
,
message
:
Dict
)
->
Optional
[
Transition
]:
"""
Find matching transition for state based on a given message
:param message: Message to match transition with
:return: Matching transition if one is found; else None
"""
for
transition
in
self
.
transitions
:
if
transition
.
matches
(
message
):
logger
.
info
(
"
Found matching transition
"
)
transition
.
action
(
execution
,
manager
)
return
transition
.
to_state
logger
.
info
(
"
No matching transitions found
"
)
return
transition
return
None
def
get_next_state
(
self
,
message
:
Dict
)
->
State
:
"""
Get next state for current transition, given a message
:param message: Message to match transition with
:return: Next state if matching transition is found; else current state
"""
transition
=
self
.
find_matching_transition
(
message
)
if
transition
:
return
transition
.
to_state
return
self
def
perform_action
(
self
,
message
:
Dict
,
execution
:
CapabilityExecutionIF
,
manager
:
ExecutionManagerIF
):
"""
Perform action for the current transition, if one exists
:param message: Message to match transition with
:param execution: Execution that is performing the action
:param manager: Execution manager to send to the action
"""
transition
=
self
.
find_matching_transition
(
message
)
if
transition
:
transition
.
action
(
execution
,
manager
)
def
final
(
self
)
->
bool
:
return
not
self
.
transitions
...
...
@@ -708,4 +735,8 @@ class CapabilityExecution(Base, CapabilityExecutionIF, JSONSerializable):
def
signal
(
self
,
manager
:
ExecutionManagerIF
,
message
:
Dict
):
logger
.
info
(
"
Signalling my state %s with this message of type %s
"
,
self
.
state_name
,
message
[
"
type
"
])
self
.
state
=
self
.
state
.
signal
(
message
,
self
,
manager
)
previous_state
=
self
.
state
# Transition execution state
self
.
state
=
self
.
state
.
get_next_state
(
message
)
# Perform action
previous_state
.
perform_action
(
message
,
self
,
manager
)
This diff is collapsed.
Click to expand it.
shared/workspaces/workspaces/capability/services/capability_service.py
+
5
−
5
View file @
2801c10d
...
...
@@ -70,15 +70,16 @@ class CapabilityService(CapabilityServiceIF):
def
complete_request
(
self
,
**
message
:
Dict
):
logger
.
info
(
f
"
RECEIVED EXECUTION-COMPLETE:
{
message
}
"
)
# Set request state to Complete
execution
=
message
[
"
subject
"
]
# Update request state
capability_request
=
self
.
capability_info
.
lookup_capability_request
(
execution
[
"
capability_request_id
"
])
capability_request
.
determine_state
()
self
.
capability_info
.
save_entity
(
capability_request
)
# Set version state to Complete
# Set version state to Complete
if the execution is indeed complete; else, leave it alone
version
=
self
.
capability_info
.
lookup_version
(
capability_request
.
id
,
execution
[
"
version_number
"
])
version
.
state
=
CapabilityVersionState
.
Complete
.
name
version
.
state
=
CapabilityVersionState
.
Complete
.
name
if
execution
[
"
state_name
"
]
==
"
Complete
"
else
version
.
state
self
.
capability_info
.
save_entity
(
version
)
capability_complete_msg
=
CapabilityMessageArchitect
(
request
=
capability_request
).
compose_message
(
...
...
@@ -92,8 +93,7 @@ class CapabilityService(CapabilityServiceIF):
execution
=
message
[
"
subject
"
]
# Set request state to Failed
# TODO(nhertz): Dynamically calculate request state based on the states of its versions
# Update request state
capability_request
=
self
.
capability_info
.
lookup_capability_request
(
execution
[
"
capability_request_id
"
])
capability_request
.
determine_state
()
self
.
capability_info
.
save_entity
(
capability_request
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment