Set up the "Flow Engine", which manages the overall coordination of a flow. It determines the order in which steps are executed (in the case of auto-transition types), handles transitions between steps, and so on. The FlowEngine should operate on a single FlowInstance object, which is supplied at initialization or when calling a static/class method.
Goal*
Expose an execute_transition method to execute the transition if it is valid and ensure that the values of the step states in question are updated to reflect their new state. (i.e. active -> completed, inactive -> active).
Needs to be able to create and/or start a new flow_instance given an instance or ID of a FlowSchema and a Person.
Should execute any available transitions of the type automatic until either the flow is completed or it arrives at a step with no automatic transitions.
When the engine cannot transition a flow anymore and it is not within an “exit step” then it should stop executing and exit.
Implementation Details*
Might be an idea to use a singleton pattern here or use a static class if we don't need to track state. However, if this complicates things then just create a FlowEngine instance each time a Flowinstance needs to be operated upon (i.e. execute a transition).
Acceptance Criteria*
Given a Person and FlowSchema the FlowEngine will create a new FlowInstance.
Given a FlowInstance the FlowEngine will execute all valid automatic transitions until it cannot execute anymore.
Given an identifier of a TransitionSchema within a FlowSchemaand a FlowInstance, the FlowEngine will execute the transition if it is valid.
Additional Information
I don't think it's worth implementing Celery at the moment. I think we should introduce this when users can define "actions" within steps. Only steps with actions should be then passed to a Celery worker.
Background & Context*
Set up the "Flow Engine", which manages the overall coordination of a flow. It determines the order in which steps are executed (in the case of auto-transition types), handles transitions between steps, and so on. The
FlowEngine
should operate on a singleFlowInstance
object, which is supplied at initialization or when calling a static/class method.Goal*
execute_transition
method to execute the transition if it is valid and ensure that the values of the step states in question are updated to reflect their new state. (i.e. active -> completed, inactive -> active).FlowSchema
and aPerson
.automatic
until either the flow is completed or it arrives at a step with no automatic transitions.Implementation Details*
Might be an idea to use a singleton pattern here or use a static class if we don't need to track state. However, if this complicates things then just create a FlowEngine instance each time a Flowinstance needs to be operated upon (i.e. execute a transition).
Acceptance Criteria*
Person
andFlowSchema
theFlowEngine
will create a newFlowInstance
.FlowInstance
theFlowEngine
will execute all validautomatic
transitions until it cannot execute anymore.TransitionSchema
within aFlowSchema
and aFlowInstance
, theFlowEngine
will execute the transition if it is valid.Additional Information
I don't think it's worth implementing Celery at the moment. I think we should introduce this when users can define "actions" within steps. Only steps with actions should be then passed to a Celery worker.
*required field.