This document describes Celery 2.4. For development docs, go here.
celery.app¶
Celery Application.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
Application¶
-
class
celery.app.
App
(main=None, loader=None, backend=None, amqp=None, events=None, log=None, control=None, set_as_current=True, accept_magic_kwargs=False, **kwargs)¶ Celery Application.
Parameters: - main – Name of the main module if running as __main__.
- loader – The loader class, or the name of the loader class to use.
Default is
celery.loaders.app.AppLoader
. - backend – The result store backend class, or the name of the
backend class to use. Default is the value of the
CELERY_RESULT_BACKEND
setting. - amqp – AMQP object or class name.
- events – Events object or class name.
- log – Log object or class name.
- control – Control object or class name.
- set_as_current – Make this the global current app.
-
main
¶ Name of the __main__ module. Required for standalone scripts.
If set this will be used instead of __main__ when automatically generating task names.
-
backend
¶ Storing/retrieving task state. See
BaseBackend
.
-
loader
¶ Current loader.
-
conf
¶ Current configuration (dict and attribute access).
-
config_from_object
(obj, silent=False)¶ Read configuration from object, where object is either a object, or the name of a module to import.
>>> celery.config_from_object("myapp.celeryconfig")
>>> from myapp import celeryconfig >>> celery.config_from_object(celeryconfig)
-
config_from_envvar
(variable_name, silent=False)¶ 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")
-
config_from_cmdline
(argv, namespace='celery')¶ Read configuration from argv.
The config
-
task
(*args, **options)¶ Decorator to create a task class out of any callable.
Examples
@task() def refresh_feed(url): return Feed.objects.get(url=url).refresh()
With setting extra options and using retry.
@task(exchange="feeds") def refresh_feed(url, **kwargs): try: return Feed.objects.get(url=url).refresh() except socket.error, exc: refresh_feed.retry(args=[url], kwargs=kwargs, exc=exc)
Calling the resulting task:
>>> refresh_feed("http://example.com/rss") # Regular <Feed: http://example.com/rss> >>> refresh_feed.delay("http://example.com/rss") # Async <AsyncResult: 8998d0f4-da0b-4669-ba03-d5ab5ac6ad5d>
-
create_task_cls
()¶ Creates a base task class using default configuration taken from this app.
-
send_task
(name, args=None, kwargs=None, countdown=None, eta=None, task_id=None, publisher=None, connection=None, connect_timeout=None, result_cls=None, expires=None, queues=None, **options)¶ Send task by name.
Parameters: - name – Name of task to execute (e.g. “tasks.add”).
- result_cls – Specify custom result class. Default is
using
AsyncResult()
.
Supports the same arguments as
apply_async()
.
-
AsyncResult
(task_id, backend=None, task_name=None)¶ Create
celery.result.BaseAsyncResult
instance.
-
TaskSetResult
(taskset_id, results, **kwargs)¶ Create
celery.result.TaskSetResult
instance.
-
broker_connection
(hostname=None, userid=None, password=None, virtual_host=None, port=None, ssl=None, insist=None, connect_timeout=None, transport=None, transport_options=None, **kwargs)¶ Establish a connection to the message broker.
Parameters: - hostname – defaults to the
BROKER_HOST
setting. - userid – defaults to the
BROKER_USER
setting. - password – defaults to the
BROKER_PASSWORD
setting. - virtual_host – defaults to the
BROKER_VHOST
setting. - port – defaults to the
BROKER_PORT
setting. - ssl – defaults to the
BROKER_USE_SSL
setting. - insist – defaults to the
BROKER_INSIST
setting. - connect_timeout – defaults to the
BROKER_CONNECTION_TIMEOUT
setting. - backend_cls – defaults to the
BROKER_TRANSPORT
setting.
:returns
kombu.connection.BrokerConnection
:- hostname – defaults to the
-
with_default_connection
(fun)¶ With any function accepting connection and connect_timeout keyword arguments, establishes a default connection if one is not already passed to it.
Any automatically established connection will be closed after the function returns.
Deprecated
Use
with app.default_connection(connection)
instead.
-
prepare_config
(c)¶ Prepare configuration before it is merged with the defaults.
-
either
(default_key, *values)¶ Fallback to the value of a configuration key if none of the *values are true.
-
merge
(l, r)¶ Like dict(a, **b) except it will keep values from a if the value in b is
None
.