芹菜速率限制不起作用



我正在尝试限制芹菜中的任务。我为它创建了一个简单的项目。但它不起作用。

这是我的程序:

celery.py

from __future__ import absolute_import
from celery import Celery
from celery.task.control import rate_limit
app = Celery('proj',
             broker='amqp://',
             backend='amqp://',
             include=['proj.tasks'])
# Optional configuration, see the application user guide.
app.conf.update(
    CELERY_TASK_RESULT_EXPIRES=3600,
)
# app.control.rate_limit('proj.tasks', '2/m')
rate_limit("proj.tasks", "2/m")
if __name__ == '__main__':
    app.start()

tasks.py

from __future__ import absolute_import
from proj.celery import app
@app.task
def add(x, y):
    return x + y

项目结构:

.
└── proj
    ├── celery.py
    ├── __init__.py
    └── tasks.py

工作:

from proj.tasks import *
add.delay(1,2)
add.delay(2,1)
add.delay(2,2)
add.delay(2,3)
add.delay(3,4)

输出:

[2015-01-29 16:41:08,331: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2015-01-29 16:41:08,345: INFO/MainProcess] mingle: searching for neighbors
[2015-01-29 16:41:09,359: INFO/MainProcess] mingle: all alone
[2015-01-29 16:41:09,389: WARNING/MainProcess] celery@viki-pc ready.
[2015-01-29 17:14:02,423: ERROR/MainProcess] Rate limit attempt for unknown task proj.tasks
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/control.py", line 155, in rate_limit
    state.app.tasks[task_name].rate_limit = rate_limit
  File "/usr/local/lib/python2.7/dist-packages/celery/app/registry.py", line 26, in __missing__
    raise self.NotRegistered(key)
NotRegistered: u'proj.tasks'
[2015-01-29 16:41:11,683: INFO/MainProcess] Received task: proj.tasks.add[4ac66ad8-8e53-43e9-b9c5-3239f330f815]
[2015-01-29 16:41:12,180: INFO/MainProcess] Received task: proj.tasks.add[3dd3167b-d621-4371-9254-af420060da14]
[2015-01-29 16:41:12,601: INFO/MainProcess] Received task: proj.tasks.add[ae1f385c-db28-4d0c-b36c-b4c467c737e2]
[2015-01-29 16:41:12,994: INFO/MainProcess] Received task: proj.tasks.add[6150984d-bce6-4cd7-871d-11b0c0909017]
[2015-01-29 16:41:13,378: INFO/MainProcess] Received task: proj.tasks.add[58800ee8-f1fa-4913-b766-75c5e1b42c80]
[2015-01-29 16:41:13,787: INFO/MainProcess] Received task: proj.tasks.add[3b5c1694-3a4c-499d-994d-02fdcb7c9e5c]
[2015-01-29 16:41:14,147: INFO/MainProcess] Received task: proj.tasks.add[b01d4923-240d-4b50-8da4-7ee2bdf656e8]
[2015-01-29 16:41:15,219: INFO/MainProcess] Received task: proj.tasks.add[6f68a52d-2e5c-428e-8a08-8b228ed87d3d]
[2015-01-29 16:41:31,683: INFO/MainProcess] Received task: proj.tasks.add[2dfb1951-9842-4722-82c8-35a0ff6651c7]
[2015-01-29 16:41:38,043: INFO/MainProcess] Received task: proj.tasks.add[93589fc2-5a5b-4d56-8564-f4cc986c7a19]
[2015-01-29 16:41:38,465: INFO/MainProcess] Task proj.tasks.add[4ac66ad8-8e53-43e9-b9c5-3239f330f815] succeeded in 0.133968511s: 7
[2015-01-29 16:41:38,521: INFO/MainProcess] Task proj.tasks.add[3dd3167b-d621-4371-9254-af420060da14] succeeded in 0.189544224002s: 7
[2015-01-29 16:41:38,522: INFO/MainProcess] Task proj.tasks.add[6150984d-bce6-4cd7-871d-11b0c0909017] succeeded in 0.188820084s: 7
[2015-01-29 16:41:38,692: INFO/MainProcess] Task proj.tasks.add[ae1f385c-db28-4d0c-b36c-b4c467c737e2] succeeded in 0.227334638999s: 7
[2015-01-29 16:41:38,743: INFO/MainProcess] Task proj.tasks.add[3b5c1694-3a4c-499d-994d-02fdcb7c9e5c] succeeded in 0.221204429999s: 7

知道为什么我会收到此错误吗? 这里可能有什么问题?

任何帮助,不胜感激。

感谢您没有对问题投反对票。

尝试向任务添加速率限制,这似乎是错误 msg 猜测的问题。

rate_limit("proj.tasks.add","2/m")

谢谢。

相关内容

  • 没有找到相关文章

最新更新