123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- =============================
- "The Big Instance" Refactor
- =============================
- The `app` branch is a work-in-progress to remove
- the use of a global configuration in Celery.
- Celery can now be instantiated, which means several
- instances of Celery may exist in the same process space.
- Also, large parts can be customized without resorting to monkey
- patching.
- Examples
- ========
- Creating a Celery instance::
- >>> from celery import Celery
- >>> celery = Celery()
- >>> celery.config_from_object("celeryconfig")
- >>> celery.config_from_envvar("CELERY_CONFIG_MODULE")
- Creating tasks:
- .. code-block:: python
- @celery.task()
- def add(x, y):
- return x + y
- Creating custom Task subclasses:
- .. code-block:: python
- Task = celery.create_task_cls()
- class DebugTask(Task):
- abstract = True
- def on_failure(self, \*args, \*\*kwargs):
- import pdb
- pdb.set_trace()
- @celery.task(base=DebugTask)
- def add(x, y):
- return x + y
- Starting a worker:
- .. code-block:: python
- worker = celery.Worker(loglevel="INFO")
- Getting access to the configuration:
- .. code-block:: python
- celery.conf.CELERY_ALWAYS_EAGER = True
- celery.conf["CELERY_ALWAYS_EAGER"] = True
- Controlling workers::
- >>> celery.control.inspect().active()
- >>> celery.control.rate_limit(add.name, "100/m")
- >>> celery.control.broadcast("shutdown")
- >>> celery.control.discard_all()
- Other interesting attributes::
- # Establish broker connection.
- >>> celery.broker_connection()
- # AMQP Specific features.
- >>> celery.amqp
- >>> celery.amqp.Router
- >>> celery.amqp.get_queues()
- >>> celery.amqp.get_task_consumer()
- # Loader
- >>> celery.loader
- # Default backend
- >>> celery.backend
- As you can probably see, this really opens up another
- dimension of customization abilities.
- Deprecations
- ============
- celery.task.PingTask
- Inferior to the ping remote control command.
- Will be removed in Celery 2.3.
- Removed deprecations
- ====================
- Use: :func:`celery.utils.timeutils.timedelta_seconds`
- Use: :func:`celery.utils.compat.defaultdict`
- Use: :func:`celery.utils.compat.all`
- Use app.send_task
- Use :data:`celery.registry.tasks`
- Aliases (Pending deprecation)
- =============================
- as in the configuration. So the key "CELERY_ALWAYS_EAGER"
- is accessed as::
- >>> app.conf.CELERY_ALWAYS_EAGER
- instead of::
- >>> from celery import conf
- >>> conf.ALWAYS_EAGER
- Default App Usage
- =================
- To be backward compatible, it must be possible
- to use all the classes/functions without passing
- an explicit app instance.
- This is achieved by having all app-dependent objects
- use :data:`~celery.app.default_app` if the app instance
- is missing.
- .. code-block:: python
- from celery.app import app_or_default
- class SomeClass(object):
- def __init__(self, app=None):
- self.app = app_or_default(app)
- The problem with this approach is that there is a chance
- that the app instance is lost along the way, and everything
- seems to be working normally. Testing app instance leaks
- is hard. The environment variable :envvar:`CELERY_TRACE_APP`
- can be used, when this is enabled :func:`celery.app.app_or_default`
- will raise an exception whenever it has to go back to the default app
- instance.
- App Dependency Tree
- -------------------
|