简体   繁体   English

Celery Python同步任务

[英]Celery python synchronous tasks

In my application, I have python celery tasks that connect to a rest API.. simple. 在我的应用程序中,我有连接到rest API的python celery任务。

The problem I have is that the API does not allow multiple resuests with the same credentials. 我的问题是API不允许具有相同凭据的多个请求。

Is there a way to have these api tasks blocking in the queue? 有没有办法让这些api任务在队列中阻塞? Meaning, If multiple requests are made around the same time, can I have the tasks sit in the queue and execute one by one, waiting for the first in the queue to finish? 意思是,如果大约在同一时间发出多个请求,我是否可以让任务坐在队列中并逐个执行,等待队列中的第一个任务完成?

Currently, in the rabbitmq message queue (with one worker), i see the tasks go through (spawned) and not wait. 当前,在rabbitmq消息队列中(有一名工作人员),我看到任务通过了(产生了),而不是等待。

I looked over documentation but could not find a simple solution. 我查看了文档,但找不到简单的解决方案。

Thanks. 谢谢。

With one worker it's impossible for celery to do more than one task at a time. 有了一个工人,芹菜不可能一次完成多个任务。 what you may be seeing is called prefetching which allows the worker to reserve tasks. 您可能会看到的称为预取,它允许工作人员保留任务。

http://docs.celeryproject.org/en/latest/userguide/optimizing.html#prefetch-limits http://docs.celeryproject.org/en/latest/userguide/optimizing.html#prefetch-limits

The default prefetch value is 4, turn it down to one and see if that fixes it. 默认的预取值为4,将其减小为1,看看是否可以解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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