Tasks
Last updated
Was this helpful?
Last updated
Was this helpful?
Tasks represent a scheduled or planned function. Tasks can give you insights in to when the function will be executed and provide insights into the success or failure of the execution.
When configuring your application's data model, it's possible to attach an to a transition. Triggering the scheduling of a task is one of the available actions. Read more about how to implement this functionality in the .
In JavaScript/TypeScript environments, our can be used to schedule a task:
See the to learn how to schedule a Task via the API
A Task object is uniquely identified within the Task Service by its id. It contains a number of attributes
functionName
- the name of the AWS Lambda function that should be executed. This function must be created in the same AWS account as the Extra Horizon deployment.
status
- Task status, see below for more information
statusChangedTimestamp
- timestamp when the status was last updated
data
- [optional] A key-value object where input to the function is provided
tags
- [optional] Descriptive keywords that improve the search experience. For example, they can be used to trace automated Tasks by adding the Task id’s to the tags list.
startTimestamp
- set when the task should start
priority
- define which tasks should get precedence in a queue
createdByApplicationId
- The application which created the task
createdByUserId
- The user who created the task
When multiple tasks need to be executed in a short period, they may be placed in a queue. Tasks are initially ordered by their startTimestamp
attribute, meaning the earliest scheduled task will be executed first.
However, if tasks are queued, the priority
attribute can be used to control the execution order. The priority
attribute overrides the startTimestamp
, so tasks with a higher priority value will be executed before those with a lower priority.
To ensure critical tasks are executed first when queuing occurs, assign them a higher priority value.
The priority
attribute can range from -9007199254740991
to 9007199254740991
. When not specified, the default value 0
is used.
The status
and statusChangedTimestamp
attributes are updated according to the Task’s execution progress. A newly created Task (status: new
) can be revoked via the Cancel a Task endpoint (status: canceled
).
Once the Task Service invokes the specified AWS Lambda function, the Task receives the inProgress
status and the execution of the code cannot be halted via Extra Horizon.
Upon successful execution of the code, AWS Lambda reports back to the Task Service and the Task status is updated to complete
.
Available since v1.3.0
If an error occurs while executing a Task, the Task Service will check if the function has defined a retry policy of the function.
When a retry policy is applicable the Task status is set to retried
and a new Task is created with the same properties. The new Task will include a retryForTaskIds
field containing the id of the original Task. In turn, the original task will receive a retriedByTaskId
field holding the id of the new Task.
If an error occurs while no restart policy is defined or the maximum number of tries have been reached the Task status is set to failed
.
If the system cannot determine the outcome of the Task execution, the Task status is also set to failed
. In such cases, an error named zombieTaskCleaned
will be included in the Task.
Available since v1.4.0
When a Task reaches the failed
status, a task_failed
event is published.
The event can be used to react to Task failures. This could for instance be used for monitoring, alerting or implementing custom retry logic.
A task_failed
event contains the following attributes:
content.id
- the id of the failed Task.
content.functionName
- the name of the function the failed Task was trying to execute.
content.error
- the error that led to the failure of the Task.
See the to learn more about retry policies.