Himanshu
Himanshu

Reputation: 2454

my_task() and my_task.delay() both work from django shell but not when scheduled

I have a celery task that works nicely when invoked from the django shell :-

>>> import my.tasks
>>> my.tasks.send
<@task: my.tasks.send>
>>> my.tasks.send()
>>> my.tasks.send.delay()
<AsyncResult: b692638a-55d6-4b70-aca8-e4e9f4f089cc>

However when scheduling it using the djcelery_crontabschedule and djcelery_periodictask it won't work and the celery console logs won't show anything related:-

[localhost] local: python manage.py celeryd --verbosity=2 -s celery -E --scheduler=djcelery.schedulers.DatabaseScheduler --loglevel=DEBUG -P eventlet -c 1000
 -------------- [email protected] v3.0.17 (Chiastic Slide)
---- **** ----- 
--- * ***  * -- [Configuration]
-- * - **** --- . broker:      redis://localhost:6379/0
- ** ---------- . app:         default:0x14fe9d0 (djcelery.loaders.DjangoLoader)
- ** ---------- . concurrency: 1000 (eventlet)
- ** ---------- . events:      ON
- ** ---------- 
- *** --- * --- [Queues]
-- ******* ---- . celery:      exchange:celery(direct) binding:celery
--- ***** ----- 

[Tasks]
  . celery.backend_cleanup
  . celery.chain
  . celery.chord
  . celery.chord_unlock
  . celery.chunks
  . celery.group
  . celery.map
  . celery.starmap
  . my.tasks.send
  ...
[2016-02-09 14:55:17,519: DEBUG/MainProcess] [Worker] Loading modules.
[2016-02-09 14:55:17,521: DEBUG/MainProcess] [Worker] Claiming components.
[2016-02-09 14:55:17,521: DEBUG/MainProcess] [Worker] Building boot step graph.
[2016-02-09 14:55:17,522: DEBUG/MainProcess] [Worker] New boot order: {ev, queues, beat, pool, mediator, autoreloader, timers, state-db, autoscaler, consumer}
[2016-02-09 14:55:17,524: DEBUG/MainProcess] Starting celery.concurrency.eventlet.TaskPool...
[2016-02-09 14:55:17,524: DEBUG/MainProcess] celery.concurrency.eventlet.TaskPool OK!
[2016-02-09 14:55:17,524: DEBUG/MainProcess] Starting celery.worker.consumer.BlockingConsumer...
[2016-02-09 14:55:17,525: WARNING/MainProcess] [email protected] ready.
[2016-02-09 14:55:17,525: DEBUG/MainProcess] consumer: Re-establishing connection to the broker...
[2016-02-09 14:55:17,530: INFO/MainProcess] consumer: Connected to redis://localhost:6379/0.
[2016-02-09 14:55:17,531: DEBUG/MainProcess] consumer: basic.qos: prefetch_count->2000
[2016-02-09 14:55:17,534: DEBUG/MainProcess] consumer: Ready to accept tasks!
[2016-02-09 14:55:17,537: INFO/MainProcess] pidbox: Connected to redis://localhost:6379/0.

Are there other logs I can check?

Upvotes: 0

Views: 163

Answers (1)

Alex Morozov
Alex Morozov

Reputation: 5993

By default a Celery worker process doesn't handle periodic tasks (like cronjobs). To make your worker process that scheduled jobs add a -B option to your startup command line:

celery -A yourproj -B worker

Upvotes: 2

Related Questions