Skip to content

Commit

Permalink
Lowercase settings and settings cleanup (radical, but backwards compa…
Browse files Browse the repository at this point in the history
…tible)

All settings are now in lowercase, and most of them have been renamed.

When loading settings the loader will look at the settings in the config
and decide if it's using old or new settings.
The settings will autmatically convert between old and new settings keys, depending
on the format the settings is in.

- It's not legal to mix new setting names and old setting names, that is unless
  the setting have two alternatives (old and new).

    An ImproperlyConfigured exceptions is rasised in this case, with help telling
    user exactly how to fix the problem.

- To support loading configuration from Django settings a new ``namespace``
  argument has been added to ``Celery`` and ``config_from_object``.

    This can be used from Django::

        app = Celery()
        app.config_from_object('django.conf:settings', namespace='CELERY_')

        # settings.py:
        CELERY_BROKER_URL = 'amqp://'
        CELERY_TASK_PROTOCOL = 2
        CELERY_TASK_ALWAYS_EAGER = True

    Or other apps wanting a prefix for some reason::

        app = Celery(namespace='celery_')
        app.conf.celery_task_always_eager = True
        app.conf.celery_task_routes = {'proj.tasks.add': 'math.yo'}

- Initial configuration directly on the app object is now lazy!

    You can set keys on an unfinalized app, without causing the tasks
    or the rest of the app to be evaluated:

        app = Celery()
        app.conf.update(
            task_default_delivery_mode=1,
            task_default_queue='default',
            task_default_exchange='default',
            task_default_routing_key='default',
        )
        app.conf.task_always_eager = True
        assert not app.configured  # <-- still not finalized

        app.config_from_object('celeryconfig')
        assert not app.configured  # <-- even now

        app.finalize()
        assert app.finalized       # <-- but now we are

        # and the config done first remains, unlike older versions of Celery.
        assert app.conf.task.default_queue == 'default'

        app.config_from_object(object())
        # but calling config_from_* again will reset everything.
        assert app.conf.task_default_queue == 'celery'

- ``config_from_*`` methods no longer override configuration set manually
  before the app was finalized.

    But calling again after the app is finalized, will clean out old
    configuration.
  • Loading branch information
ask committed Oct 30, 2015
1 parent a7d3fcf commit 53b5fdf
Show file tree
Hide file tree
Showing 121 changed files with 2,060 additions and 1,795 deletions.
42 changes: 21 additions & 21 deletions celery/app/amqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def __init__(self, app):

@cached_property
def create_task_message(self):
return self.task_protocols[self.app.conf.CELERY_TASK_PROTOCOL]
return self.task_protocols[self.app.conf.task_protocol]

@cached_property
def send_task_message(self):
Expand All @@ -257,15 +257,15 @@ def Queues(self, queues, create_missing=None, ha_policy=None,
from the current configuration."""
conf = self.app.conf
if create_missing is None:
create_missing = conf.CELERY_CREATE_MISSING_QUEUES
create_missing = conf.task_create_missing_queues
if ha_policy is None:
ha_policy = conf.CELERY_QUEUE_HA_POLICY
ha_policy = conf.task_queue_ha_policy
if max_priority is None:
max_priority = conf.CELERY_QUEUE_MAX_PRIORITY
if not queues and conf.CELERY_DEFAULT_QUEUE:
queues = (Queue(conf.CELERY_DEFAULT_QUEUE,
max_priority = conf.task_queue_max_priority
if not queues and conf.task_default_queue:
queues = (Queue(conf.task_default_queue,
exchange=self.default_exchange,
routing_key=conf.CELERY_DEFAULT_ROUTING_KEY),)
routing_key=conf.task_default_routing_key),)
autoexchange = (self.autoexchange if autoexchange is None
else autoexchange)
return self.queues_cls(
Expand All @@ -276,15 +276,15 @@ def Queues(self, queues, create_missing=None, ha_policy=None,
def Router(self, queues=None, create_missing=None):
"""Return the current task router."""
return _routes.Router(self.routes, queues or self.queues,
self.app.either('CELERY_CREATE_MISSING_QUEUES',
self.app.either('task_create_missing_queues',
create_missing), app=self.app)

def flush_routes(self):
self._rtable = _routes.prepare(self.app.conf.CELERY_ROUTES)
self._rtable = _routes.prepare(self.app.conf.task_routes)

def TaskConsumer(self, channel, queues=None, accept=None, **kw):
if accept is None:
accept = self.app.conf.CELERY_ACCEPT_CONTENT
accept = self.app.conf.accept_content
return self.Consumer(
channel, accept=accept,
queues=queues or list(self.queues.consume_from.values()),
Expand Down Expand Up @@ -442,9 +442,9 @@ def as_task_v1(self, task_id, name, args=None, kwargs=None,
)

def _create_task_sender(self):
default_retry = self.app.conf.CELERY_TASK_PUBLISH_RETRY
default_policy = self.app.conf.CELERY_TASK_PUBLISH_RETRY_POLICY
default_delivery_mode = self.app.conf.CELERY_DEFAULT_DELIVERY_MODE
default_retry = self.app.conf.task_publish_retry
default_policy = self.app.conf.task_publish_retry_policy
default_delivery_mode = self.app.conf.task_default_delivery_mode
default_queue = self.default_queue
queues = self.queues
send_before_publish = signals.before_task_publish.send
Expand All @@ -458,9 +458,9 @@ def _create_task_sender(self):
default_evd = self._event_dispatcher
default_exchange = self.default_exchange

default_rkey = self.app.conf.CELERY_DEFAULT_ROUTING_KEY
default_serializer = self.app.conf.CELERY_TASK_SERIALIZER
default_compressor = self.app.conf.CELERY_MESSAGE_COMPRESSION
default_rkey = self.app.conf.task_default_routing_key
default_serializer = self.app.conf.task_serializer
default_compressor = self.app.conf.result_compression

def publish_task(producer, name, message,
exchange=None, routing_key=None, queue=None,
Expand Down Expand Up @@ -541,12 +541,12 @@ def publish_task(producer, name, message,

@cached_property
def default_queue(self):
return self.queues[self.app.conf.CELERY_DEFAULT_QUEUE]
return self.queues[self.app.conf.task_default_queue]

@cached_property
def queues(self):
"""Queue name⇒ declaration mapping."""
return self.Queues(self.app.conf.CELERY_QUEUES)
return self.Queues(self.app.conf.task_queues)

@queues.setter # noqa
def queues(self, queues):
Expand Down Expand Up @@ -575,12 +575,12 @@ def producer_pool(self):

@cached_property
def default_exchange(self):
return Exchange(self.app.conf.CELERY_DEFAULT_EXCHANGE,
self.app.conf.CELERY_DEFAULT_EXCHANGE_TYPE)
return Exchange(self.app.conf.task_default_exchange,
self.app.conf.task_default_exchange_type)

@cached_property
def utc(self):
return self.app.conf.CELERY_ENABLE_UTC
return self.app.conf.enable_utc

@cached_property
def _event_dispatcher(self):
Expand Down
4 changes: 2 additions & 2 deletions celery/app/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
task classes in the configuration.
This prepares and performs the annotations in the
:setting:`CELERY_ANNOTATIONS` setting.
:setting:`task_annotations` setting.
"""
from __future__ import absolute_import
Expand Down Expand Up @@ -38,7 +38,7 @@ def annotate(self, task):


def prepare(annotations):
"""Expands the :setting:`CELERY_ANNOTATIONS` setting."""
"""Expands the :setting:`task_annotations` setting."""

def expand_annotation(annotation):
if isinstance(annotation, dict):
Expand Down
Loading

0 comments on commit 53b5fdf

Please sign in to comment.