I am following the instructions here:
http://celery.readthedocs.org/en/latest/userguide/periodic-tasks.html#crontab-schedules
I'm supposed to be able to do the following: from celery.schedules import crontab
In my settings.py
I have:
from kombu import serialization
serialization.registry._decoders.pop("application/x-python-serialize")
import djcelery
djcelery.setup_loader()
from celery.schedules import crontab
...
CELERYBEAT_SCHEDULE = {
'first_task': {
'task': 'apps.icecream.tasks.sync_flavors',
'schedule': crontab(minute='*/30', hour='1, 3, 6, 8-20, 22')
},
'second_task': {
'task': 'apps.robots.tasks.run_robots',
'schedule': crontab(minute='*/6')
}
}
However, I'm getting an error: "No module named schedules"
If I switch to the other way of scheduling, using timedelta, then everything is fine and I can get my periodic tasks to run:
CELERYBEAT_SCHEDULE = {
'first_task': {
'task': 'apps.icecream.tasks.sync_flavors',
'schedule': timedelta(minutes=30)
},
'second_task': {
'task': 'apps.robots.tasks.run_robots',
'schedule': timedelta(minutes=6)
}
}
Why can't I use the crontab approach?
First, open a new shell or window. In that shell, set up the same Django development environment - activate your virtual environment, or add things to your Python path, whatever you do so that you could use runserver to run your project.
To begin, let's first set up the Flask framework with Celery. Save this python script as app.py in the main project directory, and in your terminal, run: python ~/celery-scheduler/app.py . Now go to http://localhost:5000/. If everything is running fine, you should see “Hello, Flask is up and running!”
Introduction. celery beat is a scheduler; It kicks off tasks at regular intervals, that are then executed by available worker nodes in the cluster. By default the entries are taken from the beat_schedule setting, but custom stores can also be used, like storing the entries in a SQL database.
This happens because you have a celery.py
file in the same package as your settings.py
, which shadows the global celery
package.
To get around this, insert the following string at the beginning of the settings.py:
from __future__ import absolute_import
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With