In TQL, each instance of a workflow (or process) can only be executed once. However, in many circumstances, you may want a workflow to be executed multiple times, for instance, the process to update an attribute value may needs to be repeated every time a sensor event comes in. Such "repeatable workflows" are represented as process streams where each process instance is a self-contained independent copy of the original workflow [definition] running with specific arguments.
Repeatable versus non-repeatable workflows
a. Non-repeatable (single-run, non-stream) workflows (used in AppFacets)
Such workflows runs for a single time and never repeats. If you do not specify the "While" modifier for the first workflow task, a workflow will run only once. (By default a task's while = "false".) Non-repeatable workflows should be started immediately after compilation (i.e. after it is deployed) without waiting for any events for it to be activated or continued. The originating pipeline, which instantiated the workflow, will wait until the workflow completes.
Examples of non-repeatable workflows are often used in AppFacets.
placeholder for example of non-repeatable workflow
b. Repeatable (multi-run, stream) workflows
Such workflows are implemented as a stream (i.e. a sequence) of single-run instances which are called “process”, thus “stream of processes” or “process stream” terms. They are usually used to process sequences of events. Repeatable workflows are defined by using the "While" modifier (While = "true") for its tasks. Most workflows used in ThingFacets (to interact with things) are repeatable workflows. The originating pipeline, which instantiated the workflow, does not wait for the workflow (fire-and-forget).
Use While = "true" in the first task
Due to the current compiler limitation, you must use While = "true" for the first task that appears in your workflow definition (source code) in order for the compiler to recognize that this is a repeatable workflow. You do not need to specify While = "true" for the subsequent tasks in the same workflow definition.
Non-waiting versus externally-activated workflows
a. Non-waiting workflows
Instances of such workflow are started right after they are created. This is done by ensuring that all the input values of the workflow's initial task(s) have their values assigned in your source code (versus waiting for external events to give value). They are only useful if they are doing something or communicating with some other entities [en-masse] which is difficult with non-repeatable workflows.
Placeholder for example of non-waiting workflow
b. Externally-activated workflows
These are workflows which have explicit “event handler”. Instances of these workflows wait for the external event to come and then start ("external" here means external to the workflow itself). The "event handler" is written as "Event" in the workflow definition. In ThingFacet (and AppFacet) workflows, the Event is typically the ActionArgument, which is triggered by the modification of actionable attributes of the model facet.
Placeholder for example of externally-activated workflows.
Externally-continued versus internally continued workflows
a. Externally-continued workflows
These have an invoke with the WaitFor modifier. Instances of such workflows can start, work for a while and then suspend and wait for an event in the middle of task (on the waitFor). Once wait is completed they continue until the next WaitFor or process completion (The "external" here means external to the workflow itself).
Placeholder for example of externally-continued workflow
b. Internally continued workflows
Instances of these workflows suspend on pipeline operations. Conceptually it’s the same as waiting for a response after an HTTP request, only without the actual request. RFID reader is an example. The process starts by itself or by an external event, but then suspends on the pipeline operation. Once a “response” is received from the device, the process continues to the next suspension or completion. The "internal" here means the pipeline operations is internal to the workflow itself. "Internal" is not related to the source of the "response". For example, the response may come from a device outside the application.
In such workflows, it is a good practice to have a Timeout modifier on the workflow.