问题
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