Celery: Error in docs: CELERY_ROUTES -> CELERY_TASK_ROUTES

Created on 3 Sep 2018  路  3Comments  路  Source: celery/celery

CELERY_ROUTES should be CELERY_TASK_ROUTES
http://docs.celeryproject.org/en/latest/userguide/configuration.html

spent a few hours before figuring that out :(
I imagine the same applied to CELERY_QUEUES

Documentation Sprint Candidate

Most helpful comment

The docs are actually correct, but it took me a while to figure out why - I'll explain in case it helps others.

CELERY_ROUTES is the old celery setting name which has now been replaced by task_routes. However if you want to specify Celery settings in a _Django_ settings file, they must be upper-case as required by Django docs. This would mean adding TASK_ROUTES to your Django settings file, but to avoid conflict with other django settings it's recommended to prefix celery settings with CELERY_, which would result in you adding for example CELERY_TASK_ROUTES to your Django settings file. Your code would then load this into the celery app by doing something like this:

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

This would result in Celery taking CELERY_TASK_ROUTES, stripping the namespace prefix to get TASK_ROUTES, and lower-casing it to get task_routes. The result being that it will set the celery config via the new name.

In summary:

  • CELERY_ROUTES is the old celery setting name
  • CELERY_TASK_ROUTES is an upper-cased, prefixed alteration of the new setting name, commonly used to set the new setting name from a Django settings file.

Hope that helps.

(Based on my shorter comment on this stack overflow answer)

All 3 comments

could you send pr with suggested edits?

The docs are actually correct, but it took me a while to figure out why - I'll explain in case it helps others.

CELERY_ROUTES is the old celery setting name which has now been replaced by task_routes. However if you want to specify Celery settings in a _Django_ settings file, they must be upper-case as required by Django docs. This would mean adding TASK_ROUTES to your Django settings file, but to avoid conflict with other django settings it's recommended to prefix celery settings with CELERY_, which would result in you adding for example CELERY_TASK_ROUTES to your Django settings file. Your code would then load this into the celery app by doing something like this:

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

This would result in Celery taking CELERY_TASK_ROUTES, stripping the namespace prefix to get TASK_ROUTES, and lower-casing it to get task_routes. The result being that it will set the celery config via the new name.

In summary:

  • CELERY_ROUTES is the old celery setting name
  • CELERY_TASK_ROUTES is an upper-cased, prefixed alteration of the new setting name, commonly used to set the new setting name from a Django settings file.

Hope that helps.

(Based on my shorter comment on this stack overflow answer)

Was this page helpful?
0 / 5 - 0 ratings