Reputation: 619
i have a simple structure:
proj
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'}
}
)
tasks.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)
According to the parameter {'rate_limit': '2/m'}
I can run the add
task only 2 times a minute. But I can run it as many times as I want. What's wrong?
Upvotes: 5
Views: 1453
Reputation: 2083
From 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.
Upvotes: 4