本文介绍了如何立即运行芹菜时间表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样配置的芹菜计划:
I have a celery schedule which is configured like this:
CELERYBEAT_SCHEDULE = {
"runs-every-30-seconds": {
"task": "tasks.refresh",
"schedule": timedelta(hours=1)
},
}
测试后,我发现这个时间表在1小时后开始,但我想运行1小时后立即安排。
After testing I find that this schedule is started after 1 hour, but I want to run this schedule instantly and again after 1 hour.
推荐答案
如果您的意思是启动时,请在(django 1.7中的新增内容):
If you mean at startup, do it in AppConfig.ready() (new in django 1.7):
# my_app/__init__.py:
class MyAppConfig(AppConfig):
def ready(self):
tasks.refresh.delay()
另见:
如果你只是为了测试, d直接调用/延迟任务,而不是测试芹菜调度器本身。
If you're only doing this for the tests, I'd rather call/delay the tasks directly than testing the celery scheduler itself.
这篇关于如何立即运行芹菜时间表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!