我有一个正在发送两次的定期任务。我无法弄清楚原因。
芹菜配置(部分):
app.conf.CELERYBEAT_SCHEDULE = {
'email-todays-todos': {
'task': 'apps.todo.tasks.email_todays_todos',
'schedule': crontab(hour='7', minute='30')
},
'send-onboarding-emails': {
'task': 'apps.home.tasks.send_onboarding_emails',
'schedule': crontab(hour='13', minute='0')
},
}
第一个周期性任务(email_todays_todos
)发送一次没有问题,但第二个任务(send_onboarding_emails
)发送两次。
我的Procfile:
web: gunicorn appname.wsgi
worker: celery -A appname worker -l info
beat: celery -A appname beat
以下是日志中发生的事情:
Mar 10 11:00:00 appname app/beat.1: [2014-03-10 13:00:00,162: INFO/MainProcess] Scheduler: Sending due task send-onboarding-emails (apps.home.tasks.send_onboarding_emails)
Mar 10 11:00:00 appname app/beat.1: [2014-03-10 13:00:00,101: INFO/MainProcess] Scheduler: Sending due task send-onboarding-emails (apps.home.tasks.send_onboarding_emails)
Mar 10 11:00:00 appname app/worker.2: [2014-03-10 13:00:00,259: INFO/MainProcess] Received task: apps.home.tasks.send_onboarding_emails[a4dcb6ff-fa40-4a9c-beba-21c62b0bd5e5]
Mar 10 11:00:01 appname app/worker.1: [2014-03-10 13:00:00,450: INFO/MainProcess] Received task: apps.home.tasks.send_onboarding_emails[f97c546d-5876-4152-8344-96bd05c546b1]
Mar 10 11:00:05 appname app/worker.2: [2014-03-10 13:00:05,564: INFO/MainProcess] Task apps.home.tasks.send_onboarding_emails[a4dcb6ff-fa40-4a9c-beba-21c62b0bd5e5] succeeded in 5.00695208088s: True
Mar 10 11:00:07 appname app/worker.1: [2014-03-10 13:00:05,455: INFO/MainProcess] Task apps.home.tasks.send_onboarding_emails[f97c546d-5876-4152-8344-96bd05c546b1] succeeded in 4.76427294314s: True
我为工作流程运行了2个dynos,为节拍过程运行了1个dyno。
这里有什么想法吗?
答案 0 :(得分:0)
我有类似的问题。不确定这是否适合您,但我最终从我的设置文件中删除了CELERYBEAT_SCHEDULE,而是在tasks.py文件中创建了一个定期任务。只需装饰你想要运行的功能:
@periodic_task(run_every = timedelta(秒= 30))
我每30秒跑一次,但你可以把它改成你想要的任何间隔。