简体   繁体   中英

Celery: Can I execute one instance of a function at a time using Celery?

So I have a program that for example runs functions: x, y, z. Let's say that execution time for the functions is:

x -> 5 seconds
y -> 15 minutes
z -> 2 minutes

So, I'm facing a problem where when y is being executed, and I get another task for y, it also starts executing y again. So i'll have 2 y's being executed at the same time.

What I'm trying to achieve? Y being executed only once at a time. Once the first Y execution finishes, the second Y can start getting executed.

I tried looking for solutions and what I found was documentation that would let us execute one task at a time (x / y / z) however I want all of the task to be executed normally, just when we get 2 instances of y, we need the second instance to wait for the first instance to finish executing.

So we need the queue to look like: (working)

X
Y -> Y
Z

The solutions I found would make it like:

X-> Y-> Z -> Y, which is only one task at a time, doesn't matter which function.

Which is NOT what I'm looking for.

Please let me know if the question was not clear.

Thank you.

Yes, it is doable and is explained in the Ensuring a task is only executed one at a time section of the "Task Cookbook" part of the Celery documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM