Celery v0.9.0 (unstable) documentation

This Page

Executing Tasks - celery.execute

celery.execute.apply(task, args, kwargs, **options)

Apply the task locally.

This will block until the task completes, and returns a celery.result.EagerResult instance.

celery.execute.apply_async(task, args=None, kwargs=None, countdown=None, eta=None, routing_key=None, exchange=None, task_id=None, immediate=None, mandatory=None, priority=None, connection=None, connect_timeout=4, serializer=None, **opts)

Run a task asynchronously by the celery daemon(s).

Parameters:
  • task – The task to run (a callable object, or a Task instance
  • args – The positional arguments to pass on to the task (a list).
  • kwargs – The keyword arguments to pass on to the task (a dict)
  • countdown – Number of seconds into the future that the task should execute. Defaults to immediate delivery (Do not confuse that with the immediate setting, they are unrelated).
  • eta – A datetime.datetime object that describes the absolute time when the task should execute. May not be specified if countdown is also supplied. (Do not confuse this with the immediate setting, they are unrelated).
  • routing_key – The routing key used to route the task to a worker server.
  • exchange – The named exchange to send the task to. Defaults to celery.task.base.Task.exchange.
  • immediate – Request immediate delivery. Will raise an exception if the task cannot be routed to a worker immediately. (Do not confuse this parameter with the countdown and eta settings, as they are unrelated).
  • mandatory – Mandatory routing. Raises an exception if there’s no running workers able to take on this task.
  • connection – Re-use existing AMQP connection. The connect_timeout argument is not respected if this is set.
  • connect_timeout – The timeout in seconds, before we give up on establishing a connection to the AMQP server.
  • priority – The task priority, a number between 0 and 9.
  • serializer – A string identifying the default serialization method to use. Defaults to the CELERY_TASK_SERIALIZER setting. Can be pickle json, yaml, or any custom serialization methods that have been registered with carrot.serialization.registry.

Note: If the CELERY_ALWAYS_EAGER setting is set, it will be replaced by a local apply() call instead.

celery.execute.delay_task(task_name, *args, **kwargs)

Delay a task for execution by the celery daemon.

Parameters:
  • task_name – the name of a task registered in the task registry.
  • *args – positional arguments to pass on to the task.
  • **kwargs – keyword arguments to pass on to the task.
Raises celery.exceptions.NotRegistered:
 

exception if no such task has been registered in the task registry.

Return type:

celery.result.AsyncResult.

Example

>>> r = delay_task("update_record", name="George Constanza", age=32)
>>> r.ready()
True
>>> r.result
"Record was updated"