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