Executable Jobs - celery.worker.job

Jobs Executable by the Worker Server.

class celery.worker.job.TaskWrapper(task_name, task_id, task_func, args, kwargs, on_ack=None, retries=0, **opts)

Class wrapping a task to be run.

Parameters:
task_name
Kind of task. Must be a name registered in the task registry.
task_id
UUID of the task.
task_func
The tasks callable object.
args
List of positional arguments to apply to the task.
kwargs
Mapping of keyword arguments to apply to the task.
message
The original message sent. Used for acknowledging the message.
execute(loglevel=None, logfile=None)

Execute the task in a jail() and store return value and status in the task meta backend.

Parameters:
  • loglevel – The loglevel used by the task.
  • logfile – The logfile used by the task.
execute_using_pool(pool, loglevel=None, logfile=None)

Like execute(), but using the multiprocessing pool.

Parameters:
  • pool – A multiprocessing.Pool instance.
  • loglevel – The loglevel used by the task.
  • logfile – The logfile used by the task.

:returns multiprocessing.AsyncResult instance.

extend_with_default_kwargs(loglevel, logfile)

Extend the tasks keyword arguments with standard task arguments.

These are logfile, loglevel, task_id and task_name.

classmethod from_message(message, message_data, logger=None)

Create a TaskWrapper from a task message sent by celery.messaging.TaskPublisher.

Raises UnknownTaskError:
 if the message does not describe a task, the message is also rejected.
Returns:TaskWrapper instance.
on_failure(exc_info, meta)
The handler used if the task raised an exception.
on_success(ret_value, meta)
The handler used if the task was successfully processed ( without raising an exception).
celery.worker.job.jail(task_id, task_name, func, args, kwargs)

Wraps the task in a jail, which catches all exceptions, and saves the status and result of the task execution to the task meta backend.

If the call was successful, it saves the result to the task result backend, and sets the task status to "DONE".

If the call raises celery.task.base.RetryTaskError, it extracts the original exception, uses that as the result and sets the task status to "RETRY".

If the call results in an exception, it saves the exception as the task result, and sets the task status to "FAILURE".

Parameters:
  • task_id – The id of the task.
  • task_name – The name of the task.
  • func – Callable object to execute.
  • args – List of positional args to pass on to the function.
  • kwargs – Keyword arguments mapping to pass on to the function.
Returns:

the function return value on success, or the exception instance on failure.

Previous topic

Multiprocessing Worker - celery.worker

Next topic

Worker Controller Threads - celery.worker.controllers

This Page