-
Notifications
You must be signed in to change notification settings - Fork 2
Workflows: Overview
The Workflows facet provides features to implement business logic by using a sequential flow of conditioned actions, state transitions and waiting points. A workflow component consists of a state machine and a context containing all the data of the workflow.
- Businesslogic structured as state machines
- High performance and memory efficiency
- Workflow runners allow for sync and async execution
- For short- and long-living workflows
- Parallel execution of many workflow-instances
(even in single thread environments like WinForms) - Flexible waiting points
- Execution hooks via DataFlows allowing for easy testing, tracing, diagnostics and so on
- Pausable and resumable
- Serialization of workflow context
- Self-documenting
A workflow state machine is build from one or more states. In contrast to a classic finite state machine, each state consists of a number of sub-states, called steps. The steps of a state are always executed in sequential order. A step can either be an action executing specific code, a waiting point that interrupts execution and waits for a trigger to continue or a transition to another state. Additionally a step can have a condition that decides if it is executed or skipped, it is even possible to define an if-else-sequence with different options to be executed in one step.
The state machine of a workflow is always a singleton, so when multiple instances of a workflow exist they share the same instance of the state machine. Keeping a workflow running that is waiting for an event has basically no overhead (no blocking threads). That makes instantiation of workflows extremely performant and economical - it is totally feasible to run many very short-living workflows as well as using many of them in parallel for very long-living processes. That is also assisted by the fact that they support pausing and resuming and the possibilty of making them durable with just little effort by storing them in serialized form.
A Workflow is executed within a workflow runner that executes the workflow step-by-step. Each workflow runner can run many workflows in parallel. The FeatureFlowFramework provides several different workflow runners, e.g. for asynchronous or synchronous execution and it is also possible to add custom runners if needed. A workflow can be started without a specific runner, then an async default-runner is used.
Workflows offer an execution hook mechanism, triggering events via a DataFlow-connection at several points in the execution process (e.g. WorkflowFinished, StepFailed, BeginWaiting, ...). It is even possible to send custom events via this interface. Each of these ExecutionInfoEvents contains information like the current state/step, the execution phase and additional info like exceptions. That offers great possibilities e.g. for testing, execution tracing, statistics or to trigger external reactions on specific workflow events.
public class MyWorkflow : Workflow<MyWorkflow.MyStateMachine>
{
// Put here all the members of the workflow context
public class MyStateMachine : StateMachine<MyWorkflow>
{
protected override void Init()
{
// Define and initialize the statemachine here!
}
}
}