如何每天每天早上6点和下午6点运行Django celery任务? [英] How to run a Django celery task every 6am and 6pm daily?

查看:123
本文介绍了如何每天每天早上6点和下午6点运行Django celery任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有Django Celery.目前,它每天(每夜12小时)运行(午夜/00:00am和12:00 pm).但是我希望它每天每6am和6pm运行一次.我怎样才能做到这一点?预先感谢.

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.

任务:

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

推荐答案

来自

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

这篇关于如何每天每天早上6点和下午6点运行Django celery任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆