How to make two tasks mutually exclusive in the celery?

Is there a way to prevent two different tasks from running simultaneously in Celery? I was thinking of defining a new queue with concurrency level = 1 and sent these tasks to this queue, but I could not find an example. Is it possible?

Thank!

0
source share
1 answer

Yes, if you don’t need to worry about overall throughput, you can create a separate queue and have a dedicated worker with concurrency set to 1. You can create as many queues as you want and configure which of these queues each worker receives messages from.

-Q, -c, , , Queues Concurrency " ".

celery -A my_project worker -l info -Q queue1 -c 1

, , , .

CELERY_ROUTES = { 'my_app.tasks.task1': {'queue': 'queue1'}, 'my_app.tasks.task2': {'queue': 'queue2'}, }

.

task1.apply_async(queue='queue1')

+1

Source: https://habr.com/ru/post/1584648/


All Articles