Celery Beat 安排多个任务,但只运行第一个任务

问题描述 投票:0回答:1

我遇到了 Celery 的问题,我在 Celery Beat 中安排了多个任务,但只有一个任务(notify_after_sobes)正在执行。在 Celery Beat 日志中,我可以看到所有任务都已被识别和安排:

[2023-12-07 14:56:00,042] celery.beat INFO Scheduler: Sending due task send_sobes_link (celery_settings.tasks.notify_send_sobes_link)
[2023-12-07 14:56:00,042] celery.beat INFO Scheduler: Sending due task after_sobes (celery_settings.tasks.notify_after_sobes)

这是我的 Celery 配置的示例:

app = Celery('tasks')
app.config_from_object(celeryconfig)
app.conf.timezone = 'Europe/Kiev'
app.conf.enable_utc = False

app.conf.beat_schedule = {
    'notify_tomorrow_sobes_task': {
        'task': 'celery_settings.tasks.notify_tomorrow_sobes',
        'schedule': crontab(minute="00", hour="18"),
    },
    'send_sobes_link': {
        'task': 'celery_settings.tasks.notify_send_sobes_link',
        'schedule': crontab(minute="5"),
    },
    'after_sobes': {
        'task': 'celery_settings.tasks.notify_after_sobes',
        'schedule': crontab(minute="5"),
    },
}
app.autodiscover_tasks()

@app.task
def notify_tomorrow_sobes():
    asyncio.run(send_notify_tomorrow_sobes())

@app.task
def notify_send_sobes_link():
    asyncio.run(send_sobes_link())

@app.task
def notify_after_sobes():
    asyncio.run(after_sobes())

谢谢!

第二个任务(notify_send_sobes_link)失败并出现错误:NotRegistered('celery_settings.tasks.notify_send_sobes_link')

second task error img

python celery
1个回答
0
投票

看起来任务正在被 Celery Beat 识别和调度,但只有

notify_after_sobes
任务正在执行。要解决此问题:

  1. 检查其他任务(在本例中为

    send_sobes_link
    )的代码或依赖项是否存在任何问题。查看任务定义及其实现。

  2. 确保任务在 Celery 中具有正确的配置,包括正确的队列、并发设置和任何其他相关设置。

  3. 查看未执行的任务的日志,看看是否有任何错误消息或警告可以帮助您深入了解问题。

  4. 验证这些任务的安排是否存在任何冲突或重叠。检查任务是否有不同的时间表,这可能会导致它们发生冲突。

  5. 仔细检查 Celery Beat 计划设置,以确保在为每个任务指定计划时没有配置错误或错误。

如果问题仍然存在,提供有关任务定义、Celery 配置和任何错误消息的更多详细信息将有助于获得进一步的帮助。

© www.soinside.com 2019 - 2024. All rights reserved.