This document describes an older version of Celery (2.1). For the latest stable version please go here.

Executing Tasks - celery.execute

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

Apply the task locally.

Parameters:throw – Re-raise task exceptions. Defaults to the CELERY_EAGER_PROPAGATES_EXCEPTIONS setting.

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

celery.execute.apply_async(*args, **kwargs)

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

Parameters:
  • task – The Task to run.
  • args – The positional arguments to pass on to the task (a list or tuple).
  • 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 object that describes the absolute time and date of 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).
  • expires – Either a int, describing the number of seconds, or a datetime object that describes the absolute time and date of when the task should expire. The task will not be executed after the expiration time.
  • connection – Re-use existing broker connection instead of establishing a new one. 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.
  • routing_key – The routing key used to route the task to a worker server. Defaults to the tasks exchange attribute.
  • exchange – The named exchange to send the task to. Defaults to the tasks exchange attribute.
  • exchange_type – The exchange type to initalize the exchange as if not already declared. Defaults to the tasks exchange_type attribute.
  • 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). Defaults to the tasks immediate attribute.
  • mandatory – Mandatory routing. Raises an exception if there’s no running workers able to take on this task. Defaults to the tasks mandatory attribute.
  • priority – The task priority, a number between 0 and 9. Defaults to the tasks priority attribute.
  • 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. Defaults to the tasks serializer attribute.

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.

:returns celery.result.AsyncResult:

Example

>>> r = delay_task("update_record", name="George Costanza", age=32)
>>> r.ready()
True
>>> r.result
"Record was updated"
celery.execute.send_task(*args, **kwargs)

Send task by name.

Useful if you don’t have access to the Task class.

Parameters:name – Name of task to execute.

Supports the same arguments as apply_async().

Previous topic

Task Sets, Subtasks and Callbacks - celery.task.sets

Next topic

Task Result - celery.result

This Page