A Task Run is a single run of an individual task within an Execution, where an Execution is a single run of a flow. This means an Execution can have many Task Runs.

Each Task Run has associated data such as:

  • Execution ID
  • State
  • Start Date
  • End Date

Attempts

Each task run can have one or more attempts. Most task runs will have only one attempt, but you can configure retries for a task. If retries have been configured, a task failure will generate new attempts until the retry maxAttempt or maxDuration threshold is hit.

States

Similar to Executions, Task Runs cans be in a particular state.

StateDescription
CREATEDThe Execution or Task Run is waiting to be processed. This state usually means that the Execution is in a queue and is yet to be started.
RUNNINGThe Execution or Task Run is currently being processed.
SUCCESSThe Execution or Task Run has been completed successfully.
WARNINGThe Execution or Task Run exhibited unintended behavior, but the execution continued and was flagged with a warning.
FAILEDThe Execution or Task Run exhibited unintended behavior that caused the execution to fail.
RETRYINGThe Execution or Task Run is currently being retried.
RETRIEDAn Execution or Task Run exhibited unintended behavior, stopped, and created a new execution as defined by its flow-level retry policy. The policy was set to the CREATE_NEW_EXECUTION behavior.
KILLINGA command was issued that asked for the Execution or Task Run to be killed. The system is in the process of killing the associated tasks.
KILLEDAn Execution or Task Run was killed (upon request), and no more tasks will run.

Expression

You can access information about a taskrun using the {{ taskrun }} expression.

This example returns the information from {{ taskrun }}:

yaml
id: taskrun
namespace: company.team

tasks:
  - id: return
    type: io.kestra.plugin.core.debug.Return 
    format: "{{ taskrun }}"

The logs show the following:

json
{
    "id": "61TxwXQjkXfwTd4ANK6fhv",
    "startDate": "2024-11-13T14:38:38.355668Z",
    "attemptsCount": 0
}

Some Flowable Tasks, such as ForEach and ForEachItem, group tasks together. You can use the expression {{ taskrun.value }} to access the value for that task run.

In the example below, foreach will iterate twice over the values [1, 2]:

yaml
id: loop
namespace: company.team

tasks:
  - id: foreach
    type: io.kestra.plugin.core.flow.ForEach
    values: [1, 2]
    tasks:
      - id: log
        type: io.kestra.plugin.core.log.Log
        message: "{{ taskrun.value }}"

This outputs two separate log tasks, one with 1 and the other with 2.

You can also use the {{ parents }} expression to access a task run value from a parent task. Here's an example of it with ForEach:

yaml
id: loop
namespace: company.team

tasks:
  - id: foreach
    type: io.kestra.plugin.core.flow.ForEach
    values: [1, 2]
    tasks:
      - id: log
        type: io.kestra.plugin.core.log.Log
        message: "{{ taskrun.value }}"
      - id: if
        type: io.kestra.plugin.core.flow.If
        condition: "{{ true }}"
        then:
          - id: log_parent
            type: io.kestra.plugin.core.log.Log
            message: "{{ parents }}"

This will iterate through the log and if tasks twice as there are two items in values property.

The log_parent task outputs the task run value produced by foreach on the first iteration:

json
[
    {
        "taskrun": {
            "value": "1" 
        }
    }
]
Task Run JSON Object Example

Read more about it on the Expression Usage page.

Task Runs Page (EE)

If you have Kestra setup using the Kafka and Elasticsearch backend, you can view Task Runs in the UI.

taskrun_view

It's similar to the Execution View but only shows Task Runs.

Was this page helpful?