How to keep multiple independent celery queues?

By default everything goes into a default queue named celery (and this is what celery worker will process if no queue is specified) So say you have your do_work task function in django_project_root/myapp/tasks.py. You could configure the do_work task to live in it’s own queue like so: CELERY_ROUTES = { ‘myproject.tasks.do_work’: {‘queue’: ‘red’}, } Then … Read more

Celery: is there a way to write custom JSON Encoder/Decoder?

A bit late here, but you should be able to define a custom encoder and decoder by registering them in the kombu serializer registry, as in the docs: http://docs.celeryproject.org/en/latest/userguide/calling.html#serializers. For example, the following is a custom datetime serializer/deserializer (subclassing python’s builtin json module) for Django: myjson.py (put it in the same folder of your settings.py … Read more

Celery auto reload on ANY changes

Celery –autoreload doesn’t work and it is deprecated. Since you are using django, you can write a management command for that. Django has autoreload utility which is used by runserver to restart WSGI server when code changes. The same functionality can be used to reload celery workers. Create a seperate management command called celery. Write … Read more

How to make a celery task fail from within the task?

To mark a task as failed without raising an exception, update the task state to FAILURE and then raise an Ignore exception, because returning any value will record the task as successful, an example: from celery import Celery, states from celery.exceptions import Ignore app = Celery(‘tasks’, broker=”amqp://guest@localhost//”) @app.task(bind=True) def run_simulation(self): if some_condition: # manually update … Read more

How to send periodic tasks to specific queue in Celery

Periodic tasks are sent to queues by celery beat where you can do everything you do with the Celery API. Here is the list of configurations that comes with celery beat: https://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html#available-fields In your case: CELERYBEAT_SCHEDULE = { ‘installer_recalc_hour’: { ‘task’: ‘stats.installer.tasks.recalc_last_hour’, ‘schedule’: 15, # every 15 sec for test ‘options’: {‘queue’ : ‘celery_periodic’}, # … Read more