How to run celery schedule instantly?

我怕爱的太早我们不能终老 提交于 2019-12-24 03:23:42

问题


I have a celery schedule which is configured like this:

CELERYBEAT_SCHEDULE = {
    "runs-every-30-seconds": {
        "task": "tasks.refresh",
        "schedule": timedelta(hours=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.


回答1:


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

Also see: https://docs.djangoproject.com/en/1.7/ref/applications/#module-django.apps

If you're only doing this for the tests, I'd rather call/delay the tasks directly than testing the celery scheduler itself.



来源:https://stackoverflow.com/questions/23098269/how-to-run-celery-schedule-instantly

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