gpt4 book ai didi

python - rate_limit 不工作 celery

转载 作者:行者123 更新时间:2023-12-01 09:09:16 24 4
gpt4 key购买 nike

我有一个简单的结构:

  • 项目

    • celery.py
    • 任务.py
  • run_tasks.py

celery.py:

from __future__ import absolute_import, unicode_literals
from celery import Celery

app = Celery('proj',
broker='amqp://',
backend='amqp://',
include=['proj.tasks'])

app.conf.update(
result_expires=3600,
task_annotations={
'proj.tasks.add': {'rate_limit': '2/m'}
}
)

任务.py:

from __future__ import absolute_import, unicode_literals
from .celery import app


@app.task
def add(x, y):
return x + y

run_tasks.py:

 from proj.tasks import *

res = add.delay(4,4)
a = res.get()
print(a)

根据参数{'rate_limit': '2/m'},我每分钟只能运行add任务2次。但我可以根据需要多次运行它。怎么了?

最佳答案

来自Celery Docs :

Note that this is a per worker instance rate limit, and not a global rate limit. To enforce a global rate limit (e.g., for an API with a maximum number of requests per second), you must restrict to a given queue.

关于python - rate_limit 不工作 celery ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51802902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com