1
votes

Celery docs say that Celery 3.1 can work with django out of box. But tasks not working. I have tasks.py:

from celery import task
from datetime import timedelta

@task.periodic_task(run_every=timedelta(seconds=20), ignore_result=True)
    def disable_not_confirmed_users():
        print "start"

Configs:

from kombu import Exchange, Queue

CELERY_SEND_TASK_ERROR_EMAILS = True
BROKER_URL = 'amqp://guest@localhost//'
CELERY_DEFAULT_QUEUE = 'project-queue'
CELERY_DEFAULT_EXCHANGE = 'project-queue'
CELERY_DEFAULT_ROUTING_KEY = 'project-queue'
CELERY_QUEUES = (
    Queue('project-queue', Exchange('project-queue'), routing_key='project-queue'),
)

project/celery.py from future import absolute_import

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')

from django.conf import settings


app = Celery('project')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

Run celery: celery -A project worker --loglevel=INFO

But nothing not happend.

1
celery work, but task doesn't run - Nikitka
Try to run celery as celery -A fratchy worker -B --loglevel=INFO - Dima Kudosh
instead of print, try using the logging module to log an INFO mesage - Thomas
Dima Kudosh, right. It helped. - Nikitka
Have you been running celery beat? Workers are to execute tasks, but celery beat is what puts the periodic tasks in queue for execution when their time ticks. - Muhammad Tahir

1 Answers

1
votes

you should use celery beat to run periodic task.

celery -A project worker --loglevel=INFO

starts the worker, which does the actually work.

celery -A proj beat

starts the beat service, which asks the work to do the job.