bertday
bertday

Reputation: 10971

Why isn't celery periodic task working?

I'm trying to create a periodic task within a Django app.

I added this to my settings.py:

from datetime import timedelta

CELERYBEAT_SCHEDULE = {
    'get_checkins': {
        'task': 'api.tasks.get_checkins',
        'schedule': timedelta(seconds=1)
    }
}

I'm just getting started with Celery and haven't figured out which broker I want to use, so I added this as well to just bypass the broker for the time being:

if DEBUG:
    CELERY_ALWAYS_EAGER = True

I also created a celery.py file in my project folder:

from  __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'testproject.settings')
app = Celery('testproject')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

Inside my app, called api, I made a tasks.py file:

from celery import shared_task

@shared_task
def get_checkins():
    print('hello from get checkins')

I'm running the worker and beat with celery -A testproject worker --beat -l info

It starts up fine and I can see the task is registered under [tasks], but I don't see any jobs getting logged. Should be one per second. Can anyone tell why this isn't executing?

Upvotes: 2

Views: 253

Answers (1)

Pablo Fernandez
Pablo Fernandez

Reputation: 436

I looked at your post and don't see any comment on the broker you are using along with celery. Have you installed a broker like Rabbitmq? Is it running or logging some kind of error? Celery needs a broker to send and receive data.

Check the documentation here (http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#choosing-a-broker)

Upvotes: 1

Related Questions