Background execution
When an action is invoked on a process worker, it creates a system execution that runs the steps defined in the worker’s process definition. In the normal case, the execution must complete before control is returned to the caller.
A background execution allows part of the process to continue independently after control is returned to the caller. It proceeds asynchronously, and may later deliver results or status updates back to the caller.
Callback
A callback is a mechanism for delivering status or results from a background execution. It is defined by the calling process, but handled within the background execution. The callback allows the calling process's logic to resume when the background execution reaches a defined point (e.g. completion or error).
The Callback step type is used to register and manage callbacks.
Create and anchor step
The callback step type provides an anchor action, which creates a new callback record and returns a callback token that uniquely identifies it.
The step that performs the create action is known as the anchor step. The background execution uses the callback token to access the anchor step and resume the process flow by following the appropriate next step.
Response actions
The background execution can use the Callback step type to return status updates and to return a partial or full callback data. Each callback is routed to the anchor step using the callback token and results in the appropriate next branch being followed.
Status
Each callback has a status.
| create | The callback has been created but the background execution has not started (or has not indicated that it has started). |
| accept | The request has been accepted but exection has not yet started. |
| start | The background execution has started. |
| progress | The background execution is in progress. |
| complete | The background execution is complete. |
| error | The background execution has encountered an error. |
| cancel | The caller has indicated that the background process should be cancelled. |
| timeout | The callback has timed out, and should be considered cancelled. |
| orphan | The callback's parent is no longer active. |
| notFound | The notFound status may be returned when a callback cannot be found. |
| exists | Used after an exists to indicate that the token exists (but may not be valid). |
The create, accept, start and progress statuses indicate that the callback is active, and the other statuses indicate that the callback is inactive.
Parent
A background execution may itself be started by another background execution. In this case, the first background execution is known as the parent, and its callback token is referred to as the parent token.
The register action can accept a parentToken to allow the child execution to check whether the parent is still active. This is typically used to cancel or suppress child executions if the parent has already completed, failed, or timed out. It an active child detects that its parent is inactive, it sets its status to orphan.