芹菜/ redis任务快速收到多次。

时间:2014-10-15 15:30:09

标签: django celery django-celery celery-task

我使用django-celery发布了两个倒计时任务,该任务必须在2014-10-15 06:452014-10-15 08:45运行。

这是我使用--loglevel=INFO

运行时的日志
[2014-10-15 03:58:19,885: WARNING/MainProcess] celery@web468.webfaction.com ready.    
[2014-10-15 05:57:08,777: INFO/MainProcess] Received task: mysite.celery.send_session_emails[e34174e2-543d-43aa-a7b0-a32b8be81644] eta:[2014-10-15 06:45:53.701697-04:00]

[2014-10-15 05:57:08,778: INFO/MainProcess] Received task: mysite.celery.send_session_emails[08c7935f-7546-428c-a8c5-1e25e0675b12] eta:[2014-10-15 08:45:53.745062-04:00] 

[2014-10-15 06:45:54,704: INFO/MainProcess] Task mysite.celery.send_session_emails[e34174e2-543d-43aa-a7b0-a32b8be81644] succeeded in 0.683478601277s: None  
<-- Great the task at 6:45 executed correctly...


[2014-10-15 06:58:09,522: INFO/MainProcess] Received task: mysite.celery.send_session_emails[08c7935f-7546-428c-a8c5-1e25e0675b12] eta:[2014-10-15 08:45:53.745062-04:00]
[2014-10-15 07:58:09,711: INFO/MainProcess] Received task: mysite.celery.send_session_emails[08c7935f-7546-428c-a8c5-1e25e0675b12] eta:[2014-10-15 08:45:53.745062-04:00] 
<-- who published there two tasks,, i checked my code and i am sure that i didn't published them   

[2014-10-15 08:45:55,469: INFO/MainProcess] Task mysite.celery.send_session_emails[08c7935f-7546-428c-a8c5-1e25e0675b12] succeeded in 0.410996085964s: None
[2014-10-15 08:45:55,815: INFO/MainProcess] Task mysite.celery.send_session_emails[08c7935f-7546-428c-a8c5-1e25e0675b12] succeeded in 0.345424972009s: None
[2014-10-15 08:45:56,292: INFO/MainProcess] Task mysite.celery.send_session_emails[08c7935f-7546-428c-a8c5-1e25e0675b12] succeeded in 0.47599364398s: None
<-- executed 3 tasks at 8:45, i actually published one at 8:45.

我的问题是why did celery automatically published those two tasks? ie

[2014-10-15 06:58:09,522: INFO/MainProcess] Received task: mysite......
[2014-10-15 07:58:09,711: INFO/MainProcess] Received task: mysite........

1 个答案:

答案 0 :(得分:0)

  

我将芹菜经纪人转到SQLalchemy以避免这个问题。它解决了ETA任务错误的多次执行。

安装 SQLAlchemy

pip install SQLAlchemy

更新 settings.py

BROKER_URL='sqla+mysql://<mysql user>:<mysql password>@localhost/<mysql db_name>'