Celery Deprecation Timeline

Removals for version 3.2

  • Module celery.task.trace has been renamed to celery.app.trace as the celery.task package is being phased out. The compat module will be removed in version 3.2 so please change any import from:

    1. from celery.task.trace import

    to:

    1. from celery.app.trace import
  • AsyncResult.serializable() and celery.result.from_serializable will be removed.

    Use instead:

    1. >>> tup = result.as_tuple()
    2. >>> from celery.result import result_from_tuple
    3. >>> result = result_from_tuple(tup)

Removals for version 4.0

Old Task API

Compat Task Modules

  • Module celery.decorators will be removed:

    Which means you need to change:

    1. from celery.decorators import task

Into:

  1. from celery import task
  • Module celery.task may be removed (not decided)

    This means you should change:

    1. from celery.task import task

    into:

    1. from celery import task

    —and::

    from celery.task import Task

    into:

    1. from celery import Task

Note that the new Task class no longer uses classmethods for these methods:

  • delay
  • apply_async
  • retry
  • apply
  • AsyncResult
  • subtask

This also means that you can’t call these methods directly on the class, but have to instantiate the task first:

  1. >>> MyTask.delay() # NO LONGER WORKS
  2. >>> MyTask().delay() # WORKS!

TaskSet

TaskSet has been renamed to group and TaskSet will be removed in version 4.0.

Old:

  1. >>> from celery.task import TaskSet
  2. >>> TaskSet(add.subtask((i, i)) for i in xrange(10)).apply_async()

New:

  1. >>> from celery import group
  2. >>> group(add.s(i, i) for i in xrange(10))()

Magic keyword arguments

The magic keyword arguments accepted by tasks will be removed in 4.0, so you should start rewriting any tasks using the celery.decorators module and depending on keyword arguments being passed to the task, for example:

  1. from celery.decorators import task
  2. @task()
  3. def add(x, y, task_id=None):
  4. print("My task id is %r" % (task_id, ))

should be rewritten into:

  1. from celery import task
  2. @task(bind=True)
  3. def add(self, x, y):
  4. print("My task id is {0.request.id}".format(self))

Task attributes

The task attributes:

  • queue
  • exchange
  • exchange_type
  • routing_key
  • delivery_mode
  • priority

is deprecated and must be set by CELERY_ROUTES instead.

celery.result

  • BaseAsyncResult -> AsyncResult.
  • TaskSetResult -> GroupResult.
  • TaskSetResult.total -> len(GroupResult)
  • TaskSetResult.taskset_id -> GroupResult.id

Apply to: AsyncResult, EagerResult:

  1. - ``Result.wait()`` -> ``Result.get()``
  • Result.task_id() -> Result.id
  • Result.status -> Result.state.

celery.loader

  • current_loader() -> current_app.loader
  • load_settings() -> current_app.conf

Task_sent signal

The task_sent signal will be removed in version 4.0. Please use the before_task_publish and after_task_publush signals instead.

Modules to Remove

Settings

BROKER Settings

Setting nameReplace with
BROKER_HOSTBROKER_URL
BROKER_PORTBROKER_URL
BROKER_USERBROKER_URL
BROKER_PASSWORDBROKER_URL
BROKER_VHOSTBROKER_URL

REDIS Result Backend Settings

Setting nameReplace with
CELERY_REDIS_HOSTCELERY_RESULT_BACKEND
CELERY_REDIS_PORTCELERY_RESULT_BACKEND
CELERY_REDIS_DBCELERY_RESULT_BACKEND
CELERY_REDIS_PASSWORDCELERY_RESULT_BACKEND
REDIS_HOSTCELERY_RESULT_BACKEND
REDIS_PORTCELERY_RESULT_BACKEND
REDIS_DBCELERY_RESULT_BACKEND
REDIS_PASSWORDCELERY_RESULT_BACKEND

Logging Settings

Setting nameReplace with
CELERYD_LOG_LEVEL—loglevel
CELERYD_LOG_FILE—logfile</em></td></tr><tr><td><tt class="docutils literal">CELERYBEAT_LOG_LEVEL</tt></td><td><em>--loglevel</em></td></tr><tr><td><tt class="docutils literal">CELERYBEAT_LOG_FILE</tt></td><td><em>--loglevel
CELERYMON_LOG_LEVEL—loglevel
CELERYMON_LOG_FILE—loglevel`

Other Settings

Setting nameReplace with
CELERY_TASK_ERROR_WITELISTAnnotate Task.ErrorMail
CELERY_AMQP_TASK_RESULT_EXPIRESCELERY_TASK_RESULT_EXPIRES

Removals for version 2.0

  • The following settings will be removed:
Setting nameReplace with
CELERY_AMQP_CONSUMER_QUEUESCELERY_QUEUES
CELERY_AMQP_CONSUMER_QUEUESCELERY_QUEUES
CELERY_AMQP_EXCHANGECELERY_DEFAULT_EXCHANGE
CELERY_AMQP_EXCHANGE_TYPECELERY_DEFAULT_AMQP_EXCHANGE_TYPE
CELERY_AMQP_CONSUMER_ROUTING_KEYCELERY_QUEUES
CELERY_AMQP_PUBLISHER_ROUTING_KEYCELERY_DEFAULT_ROUTING_KEY
  • CELERY_LOADER definitions without class name.

    E.g. celery.loaders.default, needs to include the class name: celery.loaders.default.Loader.

  • TaskSet.run(). Use celery.task.base.TaskSet.apply_async()

    instead.

  • The module celery.task.rest; use celery.task.http instead.