state machine triggers for resuming progress from a failed state

This commit is contained in:
Philip Kalinsky 2020-02-04 13:50:06 -05:00
parent ece4b20bcf
commit c995b0963c
2 changed files with 31 additions and 0 deletions

View File

@ -94,6 +94,14 @@ def _build_transitions(csp_stages):
dest=compose_state(csp_stage, StageStates.FAILED),
)
)
transitions.append(
dict(
trigger="resume_progress_" + csp_stage.name.lower(),
source=compose_state(csp_stage, StageStates.FAILED),
dest=compose_state(csp_stage, StageStates.IN_PROGRESS),
conditions=["is_ready_resume_progress"],
)
)
return states, transitions

View File

@ -122,6 +122,22 @@ class PortfolioStateMachine(
)
self.fail_stage(stage)
elif self.current_state == FSMStates.FAILED:
# get the first trigger that starts with 'create_'
resume_progress_trigger = next(
filter(
lambda trigger: trigger.startswith("resume_progress_"),
self.machine.get_triggers(FSMStates.FAILED.name),
),
None,
)
if resume_progress_trigger:
self.trigger(resume_progress_trigger, **kwargs)
else:
app.logger.info(
f"could not locate 'resume progress trigger' for {self.__repr__()}"
)
elif state_obj.is_CREATED:
# the create trigger for the next stage should be in the available
# triggers for the current state
@ -196,6 +212,13 @@ class PortfolioStateMachine(
return True
def is_ready_resume_progress(self, event):
"""
This function guards advancing states from *_FAILED to *_IN_PROGRESS.
"""
return True
@property
def application_id(self):
return None