I am using celery in Django to periodically schedule tasks. Here are the files:
tasks.py
@periodic_task(run_every=timedelta(minutes=1))
def query():
...
celery.py
from __future__ import absolute_import, unicode_literals
from os import environ, path
from celery import Celery
from django.conf import settings
PROJECT_NAME = path.basename(path.dirname(__file__))
environ.setdefault('DJANGO_SETTINGS_MODULE', '%s.settings' % PROJECT_NAME)
app = Celery(PROJECT_NAME)
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
When I run
celery -A project worker
to start the worker, that executes fine. However, when I run
celery -A project beat
to start the beat scheduler, I get the following error:
KeyError: 'scheduler'
Why would this be occurring? I am using vagrant in PyCharm and accessing the server through vagrant ssh.
Update:
If I run
celery -A project worker --beat --scheduler django --loglevel=info
I get no error but no tasks are being received by the workers. So it looks like tasks are not being received for some reason.
Also adding
app.conf.beat_schedule = {
"query": {
"task": "query",
"schedule": crontab(minute="*", hour="*", day_of_month='*')
}
}
to celery.py and adding
@app.task(name="query")
to tasks.py does not work.