How to configure and run celerybeat

元气小坏坏 提交于 2019-12-10 21:42:59

问题


I am just getting started with celery,trying to run a periodic task.

Configured *rabbitmq** added celeryconfig.py.

And added following code in tasks.py:

from celery.decorators import periodic_task
from datetime import timedelta

@periodic_task(run_every=timedelta(seconds=2))
def every_2_seconds():
    print("Running periodic task!")

Now when I start celerybeat by typing "celerybeat" in my terminal it starts to run with follwing message

celerybeat 
celerybeat v3.0.3 (Chiastic Slide) is starting.
__    -    ... __   -        _
Configuration ->
    . broker -> amqp://arnold@localhost:5672//
    . loader -> celery.loaders.default.Loader
    . scheduler -> celery.beat.PersistentScheduler
    . db -> celerybeat-schedule
    . logfile -> [stderr]@INFO
    . maxinterval -> now (0s)
[2012-08-03 14:24:52,202: INFO/MainProcess] Celerybeat: Starting...

And there is no output of every_2_seconds method in the terminal.I am assuming I have to specify which app to run or wich tasks during the celerybeat command.How to do that?

How can I specify tasks and print the line after every 2 seconds as a periodic tasks?

Thanks.


回答1:


Add CELERY_IMPORTS=("tasks",) to your celeryconfig.py then run celerybeat.



来源:https://stackoverflow.com/questions/11792101/how-to-configure-and-run-celerybeat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!