Let's say I have created two shared tasks:
from celery import shared_task
@shared_task
def taskA():
#do something
pass
@shared_task
def taskB():
#do something else
pass
I am using celery to perform certain tasks that will be invoked by the users of my Django project. I have no issue with taskA and taskB being executed at the same time. But, if taskA is already being executed, and another user tries to invoke taskA again, I want to show them an error message.
Is there a way to do that?
The only reliable way to do this that I can think of is to have a Celery worker with concurrency set to 1, subscribed to a dedicated queue. Then you send taskA to this particular queue.
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.