Task
Last updated
Was this helpful?
Last updated
Was this helpful?
Workflow engine is configured by zen. We do not support it and do not recommend to use it anymore. Please, use any other workflow engine e.g. .
Since the 2405 release, using Aidbox in FHIR schema validation engine is recommended, which is incompatible with zen or Entity/Attribute options.
Tasks are atomic actions asynchronously executed by Aidbox or by an external executor. Tasks can be used as stand-alone operations or as part of an . It allows async operations to be more reliable, to continue work after restarts, and handle errors correctly. A typical example of task usage is asynchronous sending email or transforming a resource.
Aidbox provides several predefined tasks for routine jobs that can be called via or . They are executed in aidbox runtime, and available from the box.
When a new task is created by or by or , new resource AidboxTask
is created which stores task Params, Result, and Status, as well as some additional information regarding task execution. Bellow is an example of AidboxTask with fields explanation:
Below is a representation of a Task Instance life cycle.
After the creation of tasks, their status will be changed by Task Service to ready
, or waiting
, depending on the executeAt
field.
Tasks in the status ready
could be pulled by executors. (Either internal or external)
If the task failed and retry attempts are available, its status will be changed back to waiting
again.
Finally, the status of tasks is always changed to done
, either by an executor, a user on cancel, or Task Service on timeout, with one of the following outcomes: succeeded
, failed
or canceled.
To add a custom task:
Add the definition of the task to Aidbox Project, so TaskEngine knows about the new task.
Task Definition contains all the information necessary to define the behavior of a task instance.
Below is an example of the Aidbox Project namespace with a new task definition.
Next, a awf.task/start
request should be sent to update the task status to in-progress
. After receiving the response, your implemented task should begin execution.
Finally, upon successful execution, a awf.task/success
request should be sent. If the execution is not successful, a awf.task/fail
request should be sent instead. Both of these requests will update the task status to done
and set the corresponding outcome value.
If the task is expected to run for an extended period, awf.task/notify
requests should be periodically sent during execution. The requests inform the Task Service that the worker is still processing the task and extend the inProgressTimeout
value accordingly.
allows users to manually control Aidbox tasks by .
- Creates an instance of a defined task and makes it ready to be executed immediately or at a specified time.
- Returns the status of a task instance with the specified id.
- Cancels execution of a created task instance.
- Returns the list of all tasks.
Implement task logic using either directly or through the .
The first step for implementing a new custom task is to specify its definition in .
Once you have the task definition above, your custom task can be implemented in any programming language by using , according to the following diagram.
Initially, a request to the Task Service API should be made, either by using awf.task/long-poll
or awf.task/poll
, to fetch a new task created by .
All methods are listed below.
- Fetches a new task from the queue and changes its status from ready
to requested
, immediately returns an empty array if there are no tasks in the queue.
- Fetches a new task from the queue and changes its status from ready
to requested
. Waits for a timeout unless a new task is received. In case of timeout, returns an empty array.
- Changes the status of a task from requested
to in-progress
and start its execution.
- Notifies Task Service that a task is still alive.
- Changes the status of a task from in-progress
to done
with outcome succeeded
.
- Changes the status of a task from in-progress
to done
with outcome failed
.