问题描述
我刚开始做芹菜,试图执行一项定期任务.
I am just getting started with celery,trying to run a periodic task.
已配置* rabbitmq **添加了celeryconfig.py.
Configured *rabbitmq** added celeryconfig.py.
并在task.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!")
现在,当我通过在终端中输入"celerybeat"来启动celerybeat时,它将开始运行并跟随以下消息
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...
并且终端中没有 every_2_seconds
方法的输出.我假设我必须在celerybeat命令期间指定要运行或执行任务的应用程序.
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?
我如何指定任务并每隔2秒打印一行作为定期任务?
How can I specify tasks and print the line after every 2 seconds as a periodic tasks?
谢谢.
推荐答案
在您的celeryconfig.py中添加 CELERY_IMPORTS =("tasks",)
,然后运行celerybeat.
Add CELERY_IMPORTS=("tasks",)
to your celeryconfig.py then run celerybeat.
这篇关于如何配置和运行celerybeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!