Celery 3.1 now supports Django out of the box, please see the new tutorial
Common utils - djcelery.common¶
-
djcelery.common.
respect_language
(*args, **kwds)¶ Context manager that changes the current translation language for all code inside the following block.
Can e.g. be used inside tasks like this:
from celery import task from djcelery.common import respect_language @task def my_task(language=None): with respect_language(language): pass
-
djcelery.common.
respects_language
(fun)¶ Decorator for tasks with respect to site’s current language. You can use this decorator on your tasks together with default @task decorator (remember that the task decorator must be applied last).
See also the with-statement alternative
respect_language()
.Example:
@task @respects_language def my_task() # localize something.
The task will then accept a
language
argument that will be used to set the language in the task, and the task can thus be called like:from django.utils import translation from myapp.tasks import my_task # Pass the current language on to the task my_task.delay(language=translation.get_language()) # or set the language explicitly my_task.delay(language='no.no')