Skip to main content

Request

A request for task execution.

Attributes

AttributeTypeDescription
acknowledgedbool = FalseBoolean flag indicating whether the task message has been acknowledged to the broker.
time_startfloat = nullThe absolute timestamp when the task execution began in the worker pool.
worker_pidint = nullThe process identifier of the worker child process currently executing the task.
time_limitstuple = (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

NameTypeDescription
messageAnyThe message object containing headers, body, and delivery info.
on_ackCallable = noopCallback to execute when the task is acknowledged.
hostnamestr = nullThe hostname of the worker processing the request.
eventerAny = nullThe event dispatcher used for sending task events.
app[Celery](../../app/base/celery.md?sid=celery_app_base_celery) = nullThe Celery application instance.
connection_errorstuple = nullTuple of connection-related exceptions to catch.
request_dictdict = nullOptional dictionary to override message headers.
taskAny = nullThe task instance associated with this request.
on_rejectCallable = noopCallback to execute when the task is rejected.
bodyAny = nullThe message body; defaults to message.body if not provided.
headersdict = nullOptional headers to override message headers.
decodedbool = falseFlag indicating if the body is already decoded.
utcbool = trueFlag indicating if timestamps should use UTC.
maybe_make_awareCallable = maybe_make_awareFunction to make datetime objects timezone-aware.
maybe_iso8601Callable = maybe_iso8601Function 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

TypeDescription
dictA dictionary containing the message delivery details.

message()

@classmethod
def message() - > object

Retrieves the original message object associated with this request.

Returns

TypeDescription
objectThe underlying message instance.

request_dict()

@classmethod
def request_dict() - > dict

Provides access to the raw request dictionary containing task headers and metadata.

Returns

TypeDescription
dictThe internal dictionary representation of the task request.

body()

@classmethod
def body() - > string

Retrieves the raw body of the message.

Returns

TypeDescription
stringThe 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

TypeDescription
[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

TypeDescription
booleanTrue if UTC is enabled, False otherwise.

content_type()

@classmethod
def content_type() - > string

Retrieves the MIME type of the message body.

Returns

TypeDescription
stringThe 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

TypeDescription
stringThe encoding type (e.g., 'utf-8').

type()

@classmethod
def type() - > string

Retrieves the name of the task type to be executed.

Returns

TypeDescription
stringThe registered task name.

root_id()

@classmethod
def root_id() - > string

Retrieves the unique identifier of the root task in a workflow.

Returns

TypeDescription
stringThe root task UUID.

parent_id()

@classmethod
def parent_id() - > string

Retrieves the unique identifier of the parent task that triggered this request.

Returns

TypeDescription
stringThe parent task UUID.

argsrepr()

@classmethod
def argsrepr() - > string

Provides a string representation of the task positional arguments for logging.

Returns

TypeDescription
stringThe formatted string of arguments.

args()

@classmethod
def args() - > list

Retrieves the positional arguments for the task.

Returns

TypeDescription
listThe list of arguments to pass to the task function.

kwargs()

@classmethod
def kwargs() - > dict

Retrieves the keyword arguments for the task.

Returns

TypeDescription
dictThe 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

TypeDescription
stringThe formatted string of keyword arguments.

on_ack()

@classmethod
def on_ack() - > callable

Retrieves the callback function used to acknowledge the message.

Returns

TypeDescription
callableThe acknowledgement callback.

on_reject()

@classmethod
def on_reject() - > callable

Retrieves or sets the callback function used to reject the message.

Returns

TypeDescription
callableThe rejection callback.

hostname()

@classmethod
def hostname() - > string

Retrieves the hostname of the worker processing this request.

Returns

TypeDescription
stringThe worker hostname.

ignore_result()

@classmethod
def ignore_result() - > boolean

Indicates whether the task result should be discarded after execution.

Returns

TypeDescription
booleanTrue 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

TypeDescription
objectThe event dispatcher instance.

connection_errors()

@classmethod
def connection_errors() - > tuple

Retrieves the tuple of exceptions to be treated as connection errors.

Returns

TypeDescription
tupleA 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

TypeDescription
[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

TypeDescription
datetimeThe scheduled execution time, or None if immediate.

expires()

@classmethod
def expires() - > datetime

Retrieves or sets the expiration time for the task.

Returns

TypeDescription
datetimeThe time after which the task is considered expired.

tzlocal()

@classmethod
def tzlocal() - > object

Retrieves the local timezone configured for the application.

Returns

TypeDescription
objectThe 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

TypeDescription
booleanTrue 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

TypeDescription
stringThe task UUID.

task_name()

@classmethod
def task_name() - > string

Retrieves or sets the name of the task (alias for name).

Returns

TypeDescription
stringThe task name.

reply_to()

@classmethod
def reply_to() - > string

Retrieves the address where the task result should be sent.

Returns

TypeDescription
stringThe reply-to queue name.

replaced_task_nesting()

@classmethod
def replaced_task_nesting() - > integer

Retrieves the nesting level if this task replaced another task.

Returns

TypeDescription
integerThe nesting depth.

groups()

@classmethod
def groups() - > list

Retrieves the list of groups this task belongs to.

Returns

TypeDescription
listA list of group identifiers.

stamped_headers()

@classmethod
def stamped_headers() - > list

Retrieves the list of header keys that have been stamped on the request.

Returns

TypeDescription
listA list of header names.

stamps()

@classmethod
def stamps() - > dict

Retrieves the values of the stamped headers.

Returns

TypeDescription
dictA 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

TypeDescription
stringThe 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

NameTypeDescription
pool[BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool)The execution pool used to execute this request.

Returns

TypeDescription
objectThe 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

NameTypeDescription
loglevelintThe loglevel used by the task.
logfilestrThe logfile used by the task.

Returns

TypeDescription
anyThe return value of the executed task.

maybe_expire()

@classmethod
def maybe_expire() - > boolean

If expired, mark the task as revoked.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
pool[BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool)The pool managing the task process.
signalstringThe 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

NameTypeDescription
pool[BasePool](../../concurrency/base/basepool.md?sid=celery_concurrency_base_basepool)The pool managing the task process.
signalstringThe signal to send to the process.
emit_retrybooleanWhether to trigger a retry event after cancellation.

revoked()

@classmethod
def revoked() - > boolean

If revoked, skip task and mark state.

Returns

TypeDescription
booleanTrue 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

NameTypeDescription
typestringThe 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

NameTypeDescription
pidintThe process ID of the worker that accepted the task.
time_acceptedfloatThe 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

NameTypeDescription
softbooleanTrue if it was a soft time limit, False for hard.
timeoutfloatThe 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

NameTypeDescription
failed__retval__runtimetupleA 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

NameTypeDescription
exc_infoExceptionInfoThe 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

NameTypeDescription
exc_infoExceptionInfoThe exception information for the failure.
send_failed_eventbooleanWhether to dispatch a 'task-failed' event.
return_okbooleanIf 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

NameTypeDescription
requeuebooleanWhether 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

NameTypeDescription
safebooleanIf True, returns string representations of arguments instead of raw objects.

Returns

TypeDescription
dictA 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

TypeDescription
stringThe formatted string 'task_name[task_id]'.

chord()

@classmethod
def chord() - > dict

Retrieves the chord callback metadata from the message payload.

Returns

TypeDescription
dictThe chord definition or None.

errbacks()

@classmethod
def errbacks() - > list

Retrieves the list of error callbacks from the message payload.

Returns

TypeDescription
listA list of errback definitions.

group()

@classmethod
def group() - > string

Retrieves the group identifier for the task.

Returns

TypeDescription
stringThe group UUID.

group_index()

@classmethod
def group_index() - > integer

Retrieves the index of the task within its group.

Returns

TypeDescription
integerThe position of the task in the group.