3
votes

I use celery for doing some tasks, all tasks added by .apply_async and my script do it automatically, depends on some external conditions. I want to get result of tasks not in direct order but in reverse.

For example, I add task1 after that task2 and after that task3 and I want celery to perform tasks in following order: task1, task3, task2. (task1 first, because celery will doing this task after I add it and befire I added task2, it's ok),

How can i get this behavior?

P.S. I use redis as a broker.

1

1 Answers

1
votes

The described behavior is not possible, or at least not to a full extent. Also, this mostly depends on the broker chosen. Basically, what you want is the queue to work in LIFO mode, however this is not the case of most message brokers. At least RabbitMQ only works in FIFO mode. With RabbitMQ, you can partly achieve your goal with priorities, but as already said, it's not bulletproof and would need additional logic involved.