3

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 Answer 1

0

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.

1
  • I don't know why but with this my task runs twice, first one when I start django server, second one when I run celery worker with beat Aug 7, 2015 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.