This document describes Celery 3.0. For development docs, go here.
| Parameters: |
|
|---|
Name of the __main__ module. Required for standalone scripts.
If set this will be used instead of __main__ when automatically generating task names.
Current configuration.
The instance of the task that is being executed, or None.
Current backend instance.
Current loader instance.
Task registry.
Accessing this attribute will also finalize the app.
Broker connection pool: pool. This attribute is not related to the workers concurrency pool.
Base task class for this app.
Cleans-up after application, like closing any pool connections. Only necessary for dynamically created apps for which you can use the with statement:
with Celery(set_as_current=False) as app:
with app.connection() as conn:
pass
Returns a string with information useful for the Celery core developers when reporting a bug.
Reads configuration from object, where object is either an object or the name of a module to import.
| Parameters: | silent – If true then import errors will be ignored. |
|---|
>>> celery.config_from_object("myapp.celeryconfig")
>>> from myapp import celeryconfig
>>> celery.config_from_object(celeryconfig)
Read configuration from environment variable.
The value of the environment variable must be the name of a module to import.
>>> os.environ["CELERY_CONFIG_MODULE"] = "myapp.celeryconfig"
>>> celery.config_from_envvar("CELERY_CONFIG_MODULE")
Add default configuration from dict d.
If the argument is a callable function then it will be regarded as a promise, and it won’t be loaded until the configuration is actually needed.
This method can be compared to:
>>> celery.conf.update(d)
with a difference that 1) no copy will be made and 2) the dict will not be transferred when the worker spawns child processes, so it’s important that the same configuration happens at import time when pickle restores the object on the other side.
Decorator to create a task class out of any callable.
Examples:
@celery.task
def refresh_feed(url):
return ...
with setting extra options:
@celery.task(exchange="feeds")
def refresh_feed(url):
return ...
App Binding
For custom apps the task decorator returns proxy objects, so that the act of creating the task is not performed until the task is used or the task registry is accessed.
If you are depending on binding to be deferred, then you must not access any attributes on the returned object until the application is fully set up (finalized).
Send task by name.
| Parameters: |
|
|---|
Otherwise supports the same arguments as Task.apply_async().
Create new result instance. See AsyncResult.
Create new taskset result instance. See GroupResult.
Embeddable worker. See WorkController.
Establish a connection to the message broker.
| Parameters: |
|
|---|
:returns kombu.connection.Connection:
For use within a with-statement to get a connection from the pool if one is not already provided.
| Parameters: | connection – If not provided, then a connection will be acquired from the connection pool. |
|---|
For use within a with-statement to get a producer from the pool if one is not already provided
| Parameters: | producer – If not provided, then a producer will be acquired from the producer pool. |
|---|
Sends an email to the admins in the ADMINS setting.
Select a subset of queues, where queues must be a list of queue names to keep.
Makes this the current app for this thread.
Finalizes the app by loading built-in tasks, and evaluating pending task decorators
Helper class used to pickle this application.
Creates a group of tasks to be executed in parallel.
Example:
>>> res = group([add.s(2, 2), add.s(4, 4)]).apply_async()
>>> res.get()
[4, 8]
The apply_async method returns GroupResult.
Chains tasks together, so that each tasks follows each other by being applied as a callback of the previous task.
If called with only one argument, then that argument must be an iterable of tasks to chain.
Example:
>>> res = chain(add.s(2, 2), add.s(4)).apply_async()
is effectively
:
>>> res.get()
8
Calling a chain will return the result of the last task in the chain. You can get to the other tasks by following the result.parent‘s:
>>> res.parent.get()
4
A chord consists of a header and a body. The header is a group of tasks that must complete before the callback is called. A chord is essentially a callback for a group of tasks.
Example:
>>> res = chord([add.s(2, 2), add.s(4, 4)])(sum_task.s())
is effectively
:
>>> res.get()
12
The body is applied with the return values of all the header tasks as a list.
Describes the arguments and execution options for a single task invocation.
Used as the parts in a group or to safely pass tasks around as callbacks.
Subtasks can also be created from tasks:
>>> add.subtask(args=(), kwargs={}, options={})
or the .s() shortcut:
>>> add.s(*args, **kwargs)
| Parameters: |
|
|---|
Note that if the first argument is a dict, the other arguments will be ignored and the values in the dict will be used instead.
>>> s = subtask("tasks.add", args=(2, 2))
>>> subtask(s)
{"task": "tasks.add", args=(2, 2), kwargs={}, options={}}
Shortcut to apply_async().
Apply this task asynchronously.
| Parameters: |
|
|---|
See apply_async().
Same as apply_async() but executed the task inline instead of sending a task message.
Returns a copy of this subtask.
| Parameters: |
|
|---|
Replace the args, kwargs or options set for this subtask. These are only replaced if the selected is not None.
Add a callback task to be applied if this task executes successfully.
| Returns: | other_subtask (to work with reduce()). |
|---|
Add a callback task to be applied if an error occurs while executing this task.
| Returns: | other_subtask (to work with reduce()) |
|---|
Set arbitrary options (same as .options.update(...)).
This is a chaining method call (i.e. it returns itself).
Gives a recursive list of dependencies (unchain if you will, but with links intact).