pythondjangodjango-celeryperiodic-task

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


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()

Solution

  • 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'))