A request for task execution.
Attributes
| Attribute | Type | Description |
|---|
| acknowledged | bool = False | Boolean flag indicating whether the task message has been acknowledged to the broker. |
| time_start | float = null | The absolute timestamp when the task execution began in the worker pool. |
| worker_pid | int = null | The process identifier of the worker child process currently executing the task. |
| time_limits | tuple = (None, None) | A tuple containing the hard and soft time limits for task execution, typically extracted from the task message headers. |
Constructor
Signature
def Request(
message: Any,
on_ack: Callable = noop,
hostname: str = null,
eventer: Any = null,
app: [Celery](../../app/base/celery.md?sid=celery_app_base_celery) = null,
connection_errors: tuple = null,
request_dict: dict = null,
task: Any = null,
on_reject: Callable = noop,
body: Any = null,
headers: dict = null,
decoded: bool = false,
utc: bool = true,
maybe_make_aware: Callable = maybe_make_aware,
maybe_iso8601: Callable = maybe_iso8601
) - > null
Parameters
| Name | Type | Description |
|---|
| message | Any | The message object containing headers, body, and delivery info. |
| on_ack | Callable = noop | Callback to execute when the task is acknowledged. |
| hostname | str = null | The hostname of the worker processing the request. |
| eventer | Any = null | The event dispatcher used for sending task events. |
| app | [Celery](../../app/base/celery.md?sid=celery_app_base_celery) = null | The Celery application instance. |
| connection_errors | tuple = null | Tuple of connection-related exceptions to catch. |
| request_dict | dict = null | Optional dictionary to override message headers. |
| task | Any = null | The task instance associated with this request. |
| on_reject | Callable = noop | Callback to execute when the task is rejected. |
| body | Any = null | The message body; defaults to message.body if not provided. |
| headers | dict = null | Optional headers to override message headers. |
| decoded | bool = false | Flag indicating if the body is already decoded. |
| utc | bool = true | Flag indicating if timestamps should use UTC. |
| maybe_make_aware | Callable = maybe_make_aware | Function to make datetime objects timezone-aware. |
| maybe_iso8601 | Callable = maybe_iso8601 | Function to parse ISO8601 date strings. |
Methods
delivery_info()
@classmethod
def delivery_info() - > dict
Fetches the delivery metadata for the message, including exchange, routing key, and priority.
Returns
| Type | Description |
|---|
dict | A dictionary containing the message delivery details. |
message()
@classmethod
def message() - > object
Retrieves the original message object associated with this request.
Returns
| Type | Description |
|---|
object | The underlying message instance. |
request_dict()
@classmethod
def request_dict() - > dict
Provides access to the raw request dictionary containing task headers and metadata.
Returns
| Type | Description |
|---|
dict | The internal dictionary representation of the task request. |
body()
@classmethod
def body() - > string
Retrieves the raw body of the message.
Returns
| Type | Description |
|---|
string | The message body content. |
app()
@classmethod
def app() - > [Celery](../../app/base/celery.md?sid=celery_app_base_celery)
Retrieves the Celery application instance associated with this request.
Returns
| Type | Description |
|---|
[Celery](../../app/base/celery.md?sid=celery_app_base_celery) | The Celery app instance. |
utc()
@classmethod
def utc() - > boolean
Indicates whether the request uses UTC timestamps.
Returns
| Type | Description |
|---|
boolean | True if UTC is enabled, False otherwise. |
content_type()
@classmethod
def content_type() - > string
Retrieves the MIME type of the message body.
Returns
| Type | Description |
|---|
string | The content type (e.g., 'application/json'). |
content_encoding()
@classmethod
def content_encoding() - > string
Retrieves the character set or encoding used for the message body.
Returns
| Type | Description |
|---|
string | The encoding type (e.g., 'utf-8'). |
type()
@classmethod
def type() - > string
Retrieves the name of the task type to be executed.
Returns
| Type | Description |
|---|
string | The registered task name. |
root_id()
@classmethod
def root_id() - > string
Retrieves the unique identifier of the root task in a workflow.
Returns
| Type | Description |
|---|
string | The root task UUID. |
parent_id()
@classmethod
def parent_id() - > string
Retrieves the unique identifier of the parent task that triggered this request.
Returns
| Type | Description |
|---|
string | The parent task UUID. |
argsrepr()
@classmethod
def argsrepr() - > string
Provides a string representation of the task positional arguments for logging.
Returns
| Type | Description |
|---|
string | The formatted string of arguments. |
args()
@classmethod
def args() - > list
Retrieves the positional arguments for the task.
Returns
| Type | Description |
|---|
list | The list of arguments to pass to the task function. |
kwargs()
@classmethod
def kwargs() - > dict
Retrieves the keyword arguments for the task.
Returns
| Type | Description |
|---|
dict | The dictionary of keyword arguments to pass to the task function. |
kwargsrepr()
@classmethod
def kwargsrepr() - > string
Provides a string representation of the task keyword arguments for logging.
Returns
| Type | Description |
|---|
string | The formatted string of keyword arguments. |
on_ack()
@classmethod
def on_ack() - > callable
Retrieves the callback function used to acknowledge the message.
Returns
| Type | Description |
|---|
callable | The acknowledgement callback. |
on_reject()
@classmethod
def on_reject() - > callable
Retrieves or sets the callback function used to reject the message.
Returns
| Type | Description |
|---|
callable | The rejection callback. |
hostname()
@classmethod
def hostname() - > string
Retrieves the hostname of the worker processing this request.
Returns
| Type | Description |
|---|
string | The worker hostname. |
ignore_result()
@classmethod
def ignore_result() - > boolean
Indicates whether the task result should be discarded after execution.
Returns
| Type | Description |
|---|
boolean | True if the result is ignored, False otherwise. |
eventer()
@classmethod
def eventer() - > object
Retrieves or sets the event dispatcher used for sending task monitoring events.
Returns
| Type | Description |
|---|
object | The event dispatcher instance. |
connection_errors()
@classmethod
def connection_errors() - > tuple
Retrieves the tuple of exceptions to be treated as connection errors.
Returns
| Type | Description |
|---|
tuple | A tuple of exception classes. |
task()
@classmethod
def task() - > [Task](../../events/state/task.md?sid=celery_events_state_task)
Retrieves the task instance associated with this request.
Returns
| Type | Description |
|---|
[Task](../../events/state/task.md?sid=celery_events_state_task) | The Celery Task object. |
eta()
@classmethod
def eta() - > datetime
Retrieves the Estimated Time of Arrival for the task.
Returns
| Type | Description |
|---|
datetime | The scheduled execution time, or None if immediate. |
expires()
@classmethod
def expires() - > datetime
Retrieves or sets the expiration time for the task.
Returns
| Type | Description |
|---|
datetime | The time after which the task is considered expired. |
tzlocal()
@classmethod
def tzlocal() - > object
Retrieves the local timezone configured for the application.
Returns
| Type | Description |
|---|
object | The timezone object. |
store_errors()
@classmethod
def store_errors() - > boolean
Determines if errors should be stored in the backend even if the result is ignored.
Returns
| Type | Description |
|---|
boolean | True if errors should be persisted. |
task_id()
@classmethod
def task_id() - > string
Retrieves or sets the unique identifier for the task (alias for id).
Returns
| Type | Description |
|---|
string | The task UUID. |
task_name()
@classmethod
def task_name() - > string
Retrieves or sets the name of the task (alias for name).
Returns
| Type | Description |
|---|
string | The task name. |
reply_to()
@classmethod
def reply_to() - > string
Retrieves the address where the task result should be sent.
Returns
| Type | Description |
|---|
string | The reply-to queue name. |
replaced_task_nesting()
@classmethod
def replaced_task_nesting() - > integer
Retrieves the nesting level if this task replaced another task.
Returns
| Type | Description |
|---|
integer | The nesting depth. |
groups()
@classmethod
def groups() - > list
Retrieves the list of groups this task belongs to.
Returns
| Type | Description |
|---|
list | A list of group identifiers. |
@classmethod
def stamped_headers() - > list
Retrieves the list of header keys that have been stamped on the request.
Returns
| Type | Description |
|---|
list | A list of header names. |
stamps()
@classmethod
def stamps() - > dict
Retrieves the values of the stamped headers.
Returns
| Type | Description |
|---|
dict | A dictionary mapping stamped header names to their values. |
correlation_id()
@classmethod
def correlation_id() - > string
Retrieves the correlation ID used to match requests with responses.
Returns
| Type | Description |
|---|
string | The correlation UUID. |
execute_using_pool()
@classmethod
def execute_using_pool(
pool: [BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool)
) - > object
Used by the worker to send this task to the pool.
Parameters
| Name | Type | Description |
|---|
| pool | [BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool) | The execution pool used to execute this request. |
Returns
| Type | Description |
|---|
object | The result object from the pool's apply_async call. |
execute()
@classmethod
def execute(
loglevel: int,
logfile: str
) - > any
Execute the task in a :func:~celery.app.trace.trace_task.
Parameters
| Name | Type | Description |
|---|
| loglevel | int | The loglevel used by the task. |
| logfile | str | The logfile used by the task. |
Returns
| Type | Description |
|---|
any | The return value of the executed task. |
maybe_expire()
@classmethod
def maybe_expire() - > boolean
If expired, mark the task as revoked.
Returns
| Type | Description |
|---|
boolean | True if the task was expired and revoked, otherwise None. |
terminate()
@classmethod
def terminate(
pool: [BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool),
signal: string
)
Terminates the task execution by sending a signal to the worker process.
Parameters
| Name | Type | Description |
|---|
| pool | [BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool) | The pool managing the task process. |
| signal | string | The signal name or number to send for termination. |
cancel()
@classmethod
def cancel(
pool: [BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool),
signal: string,
emit_retry: boolean
)
Cancels the task and optionally triggers a retry event.
Parameters
| Name | Type | Description |
|---|
| pool | [BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool) | The pool managing the task process. |
| signal | string | The signal to send to the process. |
| emit_retry | boolean | Whether to trigger a retry event after cancellation. |
revoked()
@classmethod
def revoked() - > boolean
If revoked, skip task and mark state.
Returns
| Type | Description |
|---|
boolean | True if the task is revoked or expired, False otherwise. |
send_event()
@classmethod
def send_event(
type: string
)
Dispatches a monitoring event for the task if the eventer is enabled.
Parameters
| Name | Type | Description |
|---|
| type | string | The type of event to send (e.g., 'task-started'). |
on_accepted()
@classmethod
def on_accepted(
pid: int,
time_accepted: float
)
Handler called when task is accepted by worker pool.
Parameters
| Name | Type | Description |
|---|
| pid | int | The process ID of the worker that accepted the task. |
| time_accepted | float | The monotonic timestamp when the task was accepted. |
on_timeout()
@classmethod
def on_timeout(
soft: boolean,
timeout: float
)
Handler called if the task times out.
Parameters
| Name | Type | Description |
|---|
| soft | boolean | True if it was a soft time limit, False for hard. |
| timeout | float | The duration of the timeout in seconds. |
on_success()
@classmethod
def on_success(
failed__retval__runtime: tuple
)
Handler called if the task was successfully processed.
Parameters
| Name | Type | Description |
|---|
| failed__retval__runtime | tuple | A tuple containing (failed_bool, return_value, runtime_duration). |
on_retry()
@classmethod
def on_retry(
exc_info: ExceptionInfo
)
Handler called if the task should be retried.
Parameters
| Name | Type | Description |
|---|
| exc_info | ExceptionInfo | The exception information for the retry. |
on_failure()
@classmethod
def on_failure(
exc_info: ExceptionInfo,
send_failed_event: boolean,
return_ok: boolean
)
Handler called if the task raised an exception.
Parameters
| Name | Type | Description |
|---|
| exc_info | ExceptionInfo | The exception information for the failure. |
| send_failed_event | boolean | Whether to dispatch a 'task-failed' event. |
| return_ok | boolean | If True, suppresses error logging for certain shutdown states. |
acknowledge()
@classmethod
def acknowledge()
Acknowledge task.
reject()
@classmethod
def reject(
requeue: boolean
)
Rejects the task, optionally requeuing it in the broker.
Parameters
| Name | Type | Description |
|---|
| requeue | boolean | Whether the message should be returned to the queue. |
info()
@classmethod
def info(
safe: boolean
) - > dict
Returns a dictionary of information about the request, suitable for serialization.
Parameters
| Name | Type | Description |
|---|
| safe | boolean | If True, returns string representations of arguments instead of raw objects. |
Returns
| Type | Description |
|---|
dict | A dictionary containing task ID, name, arguments, and execution state. |
humaninfo()
@classmethod
def humaninfo() - > string
Returns a human-readable string identifying the task by name and ID.
Returns
| Type | Description |
|---|
string | The formatted string 'task_name[task_id]'. |
chord()
@classmethod
def chord() - > dict
Retrieves the chord callback metadata from the message payload.
Returns
| Type | Description |
|---|
dict | The chord definition or None. |
errbacks()
@classmethod
def errbacks() - > list
Retrieves the list of error callbacks from the message payload.
Returns
| Type | Description |
|---|
list | A list of errback definitions. |
group()
@classmethod
def group() - > string
Retrieves the group identifier for the task.
Returns
| Type | Description |
|---|
string | The group UUID. |
group_index()
@classmethod
def group_index() - > integer
Retrieves the index of the task within its group.
Returns
| Type | Description |
|---|
integer | The position of the task in the group. |