How to run a Django celery task every 6am and 6pm daily?

允我心安 提交于 2019-11-30 17:18:33

问题


Hi I have Django Celery in my project. Currently its running every 12hour a day (Midnight/00:00am and 12:00pm). But I want it to run every 6am and 6pm a day. How can I do that? Thanks in advance.

Task:

from celery.task import periodic_task
from celery.schedules import crontab  
from xxx.views import update_xx_task, execute_yy_task

@periodic_task(run_every=crontab(minute=0, hour='*/12'),
    queue='nonsdepdb3115', options={'queue': 'nonsdepdb3115'})
def xxx_execute_xx_task():
    execute_yy_task()
    update_xx_task()

回答1:


From the documentation, in the examples table - you can see that you can pass in multiple hours (in 24 hour time). So, as you want to run it at 6 AM and 6 PM (1800):

@periodic_task(run_every=crontab(minute=0, hour='6,18'))


来源:https://stackoverflow.com/questions/32449845/how-to-run-a-django-celery-task-every-6am-and-6pm-daily

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!