Skip to main content

task

Decorates a function to register it as a background task using a specified backend, priority, and queue name.

def task(
function: callable = null,
priority: int = DEFAULT_TASK_PRIORITY,
queue_name: string = DEFAULT_TASK_QUEUE_NAME,
backend: string = DEFAULT_TASK_BACKEND_ALIAS,
takes_context: boolean = false,
**kwargs: dict
) - > Task

Decorates a function to register it as an asynchronous task within a specified backend and queue.

Parameters

NameTypeDescription
functioncallable = nullThe function to be converted into an asynchronous task.
priorityint = DEFAULT_TASK_PRIORITYThe execution priority level assigned to the task.
queue_namestring = DEFAULT_TASK_QUEUE_NAMEThe name of the queue where the task will be dispatched for execution.
backendstring = DEFAULT_TASK_BACKEND_ALIASThe alias of the task backend responsible for processing the task.
takes_contextboolean = falseIndicates whether the task function expects the execution context as its first argument.
**kwargsdictAdditional configuration options for the task backend; note that 'run_after' is not permitted.

Returns

TypeDescription
TaskA task instance wrapping the original function, or a decorator function if used without arguments.