python - Celery periodic task doesn't start -


i using celery in django project run periodic tasks. following standard tutorial celery's website, here project structure project

|_ settings.py |_ __init__.py |_ celery_app.py (instead of celery.py) |_ app    |_ tasks.py 

relevant parts in settings.py looks -

celery_result_backend = "amqp" celery_imports = ["app.tasks"]  celery_always_eager = true      celery_result_backend = 'djcelery.backends.database:databasebackend' celerybeat_scheduler = 'djcelery.schedulers.databasescheduler'  celery_db_reuse_max = 1  celery_accept_content = ['json'] celery_task_serializer = 'json' celery_result_serializer = 'json' celery_timezone = 'america/new york'  celerybeat_schedule = {     'test_task': {         'task': 'tasks.test_task',         'schedule': timedelta(seconds=5),         'args': (),     }, } 

celery_app.py looks -

from __future__ import absolute_import import os celery import celery django.conf import settings  os.environ.setdefault('django_settings_module', 'project.settings') app = celery('project') app.config_from_object('django.conf:settings') app.autodiscover_tasks(lambda: settings.installed_apps) 

tasks.py looks -

from __future__ import absolute_import celery.utils.log import get_task_logger celery import task celery_app import app  logger = get_task_logger(__name__)  @app.task def test_task():     in range(0, 4):         logger.debug("celery test task") 

when run celery worker, can see task being discovered -

$ python manage.py celery -a project worker --loglevel=debug --app=celery_app:app   -------------- celery@-mbp.home v3.1.19 (cipater) ---- **** -----  --- * ***  * -- darwin-15.4.0-x86_64-i386-64bit -- * - **** ---  - ** ---------- [config] - ** ---------- .> app:         project:0x10d5b9a10 - ** ---------- .> transport:   amqp://sgcelery1:**@localhost:5672/sgceleryhost - ** ---------- .> results:     djcelery.backends.database:databasebackend - *** --- * --- .> concurrency: 4 (prefork) -- ******* ----  --- ***** ----- [queues]  -------------- .> celery           exchange=celery(direct) key=celery   [tasks]   . celery.backend_cleanup   . celery.chain   . celery.chord   . celery.chord_unlock   . celery.chunks   . celery.group   . celery.map   . celery.starmap   . app.tasks.test_task  [2016-04-24 23:54:55,452: info/mainprocess] connected amqp://sgcelery1:**@127.0.0.1:5672/sgceleryhost [2016-04-24 23:54:55,471: info/mainprocess] mingle: searching neighbors [2016-04-24 23:54:56,481: info/mainprocess] mingle: alone [2016-04-24 23:54:56,497: warning/mainprocess] celery@-mbp.home ready. 

and when run beat, shows task being picked settings.py, never runs.

$ python manage.py celery -a project beat --app=celery_app:app --loglevel=debug  [2016-04-24 23:55:04,059: debug/mainprocess] current schedule: <modelentry: test_task tasks.test_task(*[], **{}) {4}> 

what missing here ?

try setting celery_always_eager = false.

setting celery_always_eager = true makes tasks run synchronously without celery being used. switching false make celery beat pick , run periodically. false switch used in development mode when don't want celery process tasks.

checkout docs here


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -