python - rate_limit 不工作 celery

标签 python python-3.x celery

我有一个简单的结构:

  • 项目

    • 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/

相关文章:

python - 在 python 子进程 popen 中格式化命令

python-3.x - 使用 statsmodels.tsa.grangercausalitytests 进行简单格兰杰因果检验

python - 弹丸从曲面弹起-Pygame,Python 3

docker - Celery beat + redis with password抛出No Auth异常

python - io/cpu 绑定(bind)任务的 Celery 并发配置

python - 无法使用python的mysql.connector连接到mysql

python - 使用 SUDS 将多个参数传递给 SOAP web 服务

unicode - Python 3是使用sys.stdout.buffer.write()好的样式吗?

python - 集成 Tornado 与 celery : RuntimeError: tornado-redis must be installed to use the redis backend

python - scrapy item 对象错误