Workflow
Introduction
Workflow allows orchestrating a series of tasks. Workflow in Aidbox is implemented through a special decision task, an instance of which is created on every event of workflow, thus a logic behind workflow could be implemented as an executor for this task.
We plan to add SDK for different programming languages to allow the implementation of workflow as a code on the client side. Also, we plan to introduce DSL to describe simple workflow inside Aidbox Configuration Project.
Workflow instance
When a new workflow is created by Workflow User API or by Services, new resource AidboxWorkflow
is created which stores workflow Params, Result, and Status, as well as some additional information regarding workflow execution. Bellow is an example of AidboxWorkflow with fields explanation:
Workflow statuses and outcomes
Below is a representation of a Workflow Instance life cycle.
After the workflow is created, the decision task with the same definition is created to move the workflow to the in-progress
state and to execute the workflow body until the new internal workflow activity is started. Then the decision task is completed with a successful outcome.
When the started activity is executed, the new decision task should execute the workflow body again to start the next activities. This process is repeated until the last activity is finished or some activity is finished with an error. After that, the workflow will change to the status done
with one of the possible outcomes.
Workflow User API
Workflow User API allows users to manually control Aidbox workflows by RPC methods.
Workflow Implementation
To add a custom workflow:
Add the definition of the workflow to Aidbox Project, so Task Service knows about the new task.
Implement decision tasks logic using Executor API either directly or through the SDK.
1. Specify Workflow Definition
The first step for implementing a new custom workflow is to specify its definition in Aidbox configuration project .
Workflow Definition contains all the information necessary to define the behavior of a workflow instance.
Below is an example of the Aidbox Project namespace with a new workflow definition.
2. Implement Workflow
We are now preparing Aidbox Workflow/Task SDK. By using it, you can probably simplify this step if you use one of the following languages: Typescript, Python, or .NET.
Once you have the workflow definition above, your custom workflow can be implemented in any programming language by using Task Executor API and a decision task.
The decision task is a predefined task to implement workflow and once a workflow is started, this task is executed each time when a task started by workflow is completed.
Suppose that we are implementing a simple workflow, in which we want to start Task-1 first, and only after its successful completion start Task-2. Successful completion of Task-2 means that this workflow was completed successfully. Thus, we need a decision task as the following flowchart indicates.
Given that the decision tasks are executed repeatedly, we need to determine which action it should take each time, using conditional branching.
Here, to run Task-1, the decision task returns action:
awf.workflow.action/schedule-task
with the definition for Task-1, the unique label within this workflow, and the parameters for Task-1.
The last decision task must return the result of the workflow with the awf.workflow.action/complete-workflow
action, and it changes the workflow status to done
.
Last updated