Lifecycle of workflows

When talking about the lifecycle of a workflow, it is important to distinguish the workflow definition from the workflow instances. Workflow instances are the executable processes at runtime. One or multiple workflow instances can be created based on one single workflow definition. 

The lifecycle of one single workflow instance includes: Creation, Activation and Execution, Waiting, and Completion and Deletion.

In TQL and ADL in general, one instance of a workflow is executed only once and will be removed to trash as soon as it completes.

A repeatable workflow (definition) can turn into multiple workflow instances. These workflow instances can run asynchronously with each other (in parallel).

When a workflow definition is deployed (along with the Model that contains it), the A-Stack will create workflow instances based on the workflow "Limit" modifier value and let them sit in the buffer waiting to be activated. For example, if Limit = "3", there will be at most 3 instances of the same workflow (from the same model definition) in the buffer at any time.

The workflow instances can be activated when the ActionArgument of the first workflow task arrives (In ThingModels this is triggered by the actionable attribute value changes). Multiple instances of the same workflow can be running at the same time, subject to the workflow modifier "Live". For example, if Live = "2", 2 instances of the same workflow (from the same model definition) can run at the same time.

Each workflow instance is removed upon completion, as described above. New instances can be activated. In the case where the actionable attribute has the modifier Update = "auto", a new instance of the workflow will be automatically activated as soon as a previous instance is completed.

A non-repeatable workflow can only have on instance and run only once. The single instance is activated right after the workflow definition is deployed (along the the Model that contains it).