在芹菜启动后,我有以下输出:
[2022-12-24 17:42:25,851: INFO/MainProcess] Connected to redis://localhost:6379//
[2022-12-24 17:42:25,854: INFO/MainProcess] mingle: searching for neighbors
[2022-12-24 17:42:26,506: INFO/Beat] beat: Starting...
[2022-12-24 17:42:26,862: INFO/MainProcess] mingle: all alone
[2022-12-24 17:42:26,881: INFO/MainProcess] celery@Bulrathi-Mac-mini.local ready.
表示节拍在启动时卡住(实际上,周期性任务没有执行)。
我像这样开始芹菜:
celery -A app.celery worker -B -l info
我的代码是
from datetime import timedelta
from celery import Celery
from celery.utils.log import get_task_logger
celery = Celery(
__name__,
broker='redis://localhost:6379',
include=['tasks']
)
celery.conf.timezone = 'UTC'
logger = get_task_logger(__name__)
@celery.task
def periodic_task():
logger.debug('yay')
CELERYBEAT_SCHEDULE = {
'every-second': {
'task': 'periodic_task',
'schedule': timedelta(seconds=1),
}
}
我搜索了类似的问题,但没有找到任何合适的解决方案。非常感谢您的帮助,提前感谢您。
你可以尝试将celery beat作为一个单独的服务来执行,并检查你的配置:
celery -A app.celery beat -l debug