Skip to main content

create_request_cls

Creates a specialized Request class for a specific task and execution pool, defining how the task is executed within the pool and how success or failure events are handled.

def create_request_cls(
base: class,
task: Task,
pool: TaskPool,
hostname: string,
eventer: EventDispatcher,
ref: callable,
revoked_tasks: set,
task_ready: callable,
trace: callable = None,
app: Celery = current_app
) - > class

Dynamically creates a specialized Request class tailored to a specific task and execution environment. This factory function captures task-specific configurations like time limits and acknowledgement policies to ensure the resulting Request instances behave correctly when executed in the worker pool.

Parameters

NameTypeDescription
baseclassThe base class from which the new Request class will inherit.
taskTaskThe task instance providing configuration metadata such as time limits and acknowledgement settings.
poolTaskPoolThe execution pool used to asynchronously dispatch the task for processing.
hostnamestringThe worker node's hostname used for identifying the source of task events.
eventerEventDispatcherThe event dispatcher used to send real-time monitoring updates like success or failure notifications.
refcallableA reference-creation function, typically weakref.ref, used to track the task result without preventing garbage collection.
revoked_taskssetA collection of task IDs that have been cancelled and should not be executed.
task_readycallableA callback function triggered when a task completes its execution cycle.
tracecallable = NoneThe tracing function used to wrap the task execution; defaults to a fast or standard tracer based on app configuration.
appCelery = current_appThe application instance providing configuration context for tracing and execution.

Returns

TypeDescription
classA subclass of the provided base class, augmented with task-specific execution logic and event handling.