Skip to main content

Context

Task request variables (Task.request).

Attributes

AttributeTypeDescription
argstuple = nullPositional arguments passed to the task for execution.
callbackslist = nullList of task signatures to be executed upon successful completion of the task.
called_directlyboolean = trueFlag indicating if the task was executed locally without a broker.
chainlist = nullList of task signatures forming a chain where this task is a member.
chorddict = nullThe chord callback signature if this task is part of a chord header.
correlation_idstring = nullUnique identifier used to correlate request and response messages.
delivery_infodict = nullDictionary containing message delivery metadata such as exchange and routing key.
errbackslist = nullList of task signatures to be executed if the task fails.
etadatetime = nullThe scheduled estimated time of arrival for the task execution.
expiresdatetime = nullThe expiration time after which the task should be discarded.
groupstring = nullThe unique identifier of the group if the task is part of a group.
group_indexint = nullThe zero-based index of the task within its group.
headersdict = nullMapping of custom message headers sent with the task.
hostnamestring = nullThe name of the worker node instance executing the task.
idstring = nullThe unique UUID of the task instance.
ignore_resultboolean = falseFlag to disable storing the task return value in the result backend.
is_eagerboolean = falseIndicates if the task is being executed locally in the client process.
kwargsdict = nullKeyword arguments passed to the task for execution.
logfilestring = nullThe file path where task execution logs are written.
loglevelint = nullThe logging severity level used during task execution.
originstring = nullThe name of the node that sent the task.
parent_idstring = nullThe unique identifier of the task that spawned this task.
propertiesdict = nullAdditional message properties provided by the broker.
retriesint = 0The number of times the current task has been retried.
reply_tostring = nullThe address of the queue where the result should be sent.
replaced_task_nestingint = 0Counter tracking the depth of task replacement nesting.
root_idstring = nullThe unique identifier of the first task in the workflow chain.
shadowstring = nullAn alternative name for the task to be used in logs and monitoring.
tasksetstring = nullCompatibility alias for the group identifier.
timelimittuple = nullA tuple containing the hard and soft time limits for task execution.
time_limitfloat = nullThe maximum number of seconds the task can run before being terminated.
soft_time_limitfloat = nullThe number of seconds before a SoftTimeLimitExceeded exception is raised.
utcboolean = nullFlag indicating if timestamps should use the UTC timezone.
stamped_headerslist = nullList of header keys that have been cryptographically stamped.
stampsdict = nullDictionary containing cryptographic stamps for message integrity.

Constructor

Signature

def Context(
*args: tuple,
**kwargs: dict
) - > null

Parameters

NameTypeDescription
*argstupleVariable length argument list used to update the context attributes.
**kwargsdictArbitrary keyword arguments used to update the context attributes.

Signature

def Context(
*args: any,
**kwargs: any
) - > null

Parameters

NameTypeDescription
*argsanyPositional arguments used to populate the context dictionary.
**kwargsanyKeyword arguments representing task request variables and metadata.

Methods


update()

@classmethod
def update(
*args: any,
**kwargs: any
) - > null

Updates the context state and synchronizes time limit attributes if the 'timelimit' key is modified.

Parameters

NameTypeDescription
*argsanyMappings or iterables of pairs used to update the context attributes.
**kwargsanyAttribute names and values to be merged into the context.

Returns

TypeDescription
nullNothing is returned.

clear()

@classmethod
def clear() - > null

Removes all attributes and data from the current context instance.

Returns

TypeDescription
nullNothing is returned.

get()

@classmethod
def get(
key: str,
default: any
) - > any

Retrieves a context attribute by name, falling back to a default value if the attribute does not exist.

Parameters

NameTypeDescription
keystrThe name of the context attribute to retrieve.
defaultanyThe value to return if the specified key is not found.

Returns

TypeDescription
anyThe value of the requested attribute or the specified default.

as_execution_options()

@classmethod
def as_execution_options() - > dict

Converts the current context into a dictionary of execution options suitable for task routing and execution.

Returns

TypeDescription
dictA dictionary containing task IDs, routing info, time limits, and filtered headers.

children()

@classmethod
def children() - > list

Provides access to the list of child tasks spawned within this context, initializing it if necessary.

Returns

TypeDescription
listA list of child task references.