是否有一种方法可以禁止在Celery中同时运行两个不同的任务?我当时正在考虑定义一个新的并发级别为1的队列,并将这些任务发送到该队列,但是我找不到一个示例.有可能吗?
Is there a way to disallow two different tasks to run simultaneously in Celery? I was thinking about defining a new queue with concurrency level=1, and send those tasks to that queue, but I couldn't find an example. Is that possible?
谢谢!
推荐答案是的,如果您不必担心整体吞吐量,则可以创建一个单独的队列并将专用的并发设置为1.可以根据需要创建任意数量的队列,并配置每个工作人员从哪个队列接收消息.
Yes, if you don't need to worry about overall throughput it is possible to 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 those queues each worker receives messages from.
启动工作程序时,可以传递 -Q 参数设置其队列,并传递 -c 参数设置其使用的线程数,如队列和
When starting the worker, you can pass the -Q parameter to set its queues and the -c parameter to set how many threads it uses, as discussed in the Queues and Concurrency sections of the Workers Guide.
celery-一个my_project worker -l info -Q queue1 -c 1
然后,您可以使用路由指南.
CELERY_ROUTES = {'my_app.tasks.task1':{'queue':'queue1'},'my_app.tasks.task2':{'queue':'queue2'},}
或者,您可以在提交每个任务实例时根据呼叫任务指南.
Alternatively, you can specify the queue at the time you submit each task instance based on the Calling Tasks Guide.
task1.apply_async(queue ='queue1')
更多推荐
如何在Celery中使两个任务互斥?
发布评论