when run celery -a tasks2.celery worker -b want see "celery task" printed every second. nothing printed. why isn't working?
from app import app celery import celery datetime import timedelta celery = celery(app.name, broker='amqp://guest:@localhost/', backend='amqp://guest:@localhost/') celery.conf.update(celery_task_result_expires=3600,) @celery.task def add(x, y): print "celery task" return x + y celerybeat_schedule = { 'add-every-30-seconds': { 'task': 'tasks2.add', 'schedule': timedelta(seconds=1), 'args': (16, 16) }, } this output after staring worker , beat:
[tasks] . tasks2.add [info/beat] beat: starting... [info/mainprocess] connected amqp://guest:**@127.0.0.1:5672// [info/mainprocess] mingle: searching neighbors [info/mainprocess] mingle: alone
you wrote schedule, didn't add celery config. beat saw no scheduled tasks send. example below uses celery.config_from_object(__name__) pick config values current module, can use other config method well.
once configure properly, see messages beat sending scheduled tasks, output tasks worker receives , runs them.
from celery import celery datetime import timedelta celery = celery(__name__) celery.config_from_object(__name__) @celery.task def say_hello(): print('hello, world!') celerybeat_schedule = { 'every-second': { 'task': 'example.say_hello', 'schedule': timedelta(seconds=5), }, } $ celery -a example.celery worker -b -l info [tasks] . example.say_hello [2015-07-15 08:23:54,350: info/beat] beat: starting... [2015-07-15 08:23:54,366: info/mainprocess] connected amqp://guest:**@127.0.0.1:5672// [2015-07-15 08:23:54,377: info/mainprocess] mingle: searching neighbors [2015-07-15 08:23:55,385: info/mainprocess] mingle: alone [2015-07-15 08:23:55,411: warning/mainprocess] celery@netsec-ast-15 ready. [2015-07-15 08:23:59,471: info/beat] scheduler: sending due task every-second (example.say_hello) [2015-07-15 08:23:59,481: info/mainprocess] received task: example.say_hello[2a9d31cb-fe11-47c8-9aa2-51690d47c007] [2015-07-15 08:23:59,483: warning/worker-3] hello, world! [2015-07-15 08:23:59,484: info/mainprocess] task example.say_hello[2a9d31cb-fe11-47c8-9aa2-51690d47c007] succeeded in 0.0012782540870830417s: none
Comments
Post a Comment