New in 0.16.2

v0.16.3

Service

Task Context

In some cases, it is useful to understand more about the context in which a task is executed.

The io.infinitic.tasks.Task class provides the following static properties:

NameTypeDescription
taskIdStringUnique identifier of the task
serviceNameStringName of the Service (taken from the @Name annotation if provided, otherwise defaulting to the service's interface name)
taskNameStringName of the task (taken from the @Name annotation if provided, otherwise defaulting to the service's method name)
workflowIdString?Unique identifier of the workflow (if part of a workflow)
workflowNameString?Name of the workflow (if part of a workflow)
tagsSet<String>Tags provided when dispatching the task
metaMap<String, ByteArray>Metadata provided when dispatching the task
retryIndex IntegerNumber of times the task was automatically retried
retrySequenceIntegerNumber of times the task was manually retried
lastErrorExecutionError?If any, the error during the previous attempt
batchKeyString?If any, the batch key provided when the task was dispatched
clientInfiniticClientAn InfiniticClient that can be used inside the task

The task context is injected by the Service worker executing the task, and is only accessible from the thread that started:

  • the task method
  • the getTimeoutSeconds method
  • the getSecondsBeforeRetry method

In tests, io.infinitic.tasks.TaskContext can be mocked and injected through Task.setContext(mockedTaskContext) before running a test that uses the task's context.

tags

The tags property of the task context is an immutable set of strings. Its value is defined when dreating the Service stub before dispatching the task:

meta

The meta property of the task context is a mutable map of strings to arrays of bytes. Its value is defined when creating the Service stub before dispatching the task:

The meta property is mutable and can be read and write during the task execution and its retries.

retryIndex

The retryIndex property of the task context indicates the current number of retry attempts. It starts at 0 and is incremented when a task is automatically retried:

Tasks retries

When a task is manually retried, the retryIndex property is reset to 0.

retrySequence

The retrySequence property of the task context indicates the current number of manual retries. It starts at 0 and is incremented when a task is manually retried:

Tasks retries

lastError

If not null (when retryIndex >= 1), the lastError property is a data object representing the exception thrown during the last task attempt. This ExecutionError instance has the following properties:

NameTypeDescription
workerNameStringName of the worker where the previous Exception was thrown
nameStringName of the previous Exception
messageStringMessage of the previous Exception
stackTraceToStringStringStringified stack trace of the previous Exception
causeExecutionError?Cause of the previous Exception
Previous
Deployment