2

我在我的 django 程序中使用 celery 3.1.17 和 redis 作为代理版本 3.0.2。它在 Ubuntu 14.04 上运行。

在设置中,我将 CELERYBEAT_SCHEDULE 定义为:

CELERYBEAT_SCHEDULE = {
    'task1': {
        'task': 'api.tasks.exsample.task1',
        'schedule': crontab(hour=1, minute=0),
        'args': ()
    },
    'task2': {
        'task': 'api.tasks.exsample.task2',
        'schedule': crontab(hour=1, minute=30),
        'args': ()
    },
    'task3': {
        'task': 'api.tasks.exsample.task3',
        'schedule': crontab(hour=2, minute=0),
        'args': ()
    },
    'task4': {
        'task': 'api.tasks.exsample.task4',
        'schedule': crontab(hour=2, minute=30),
        'args': ()
    },
    'task5': {
        'task': 'api.tasks.exsample.task5',
        'schedule': crontab(hour=2, minute=40),
        'args': ()
    },
    'task6': {
        'task': ''api.tasks.exsample.task6',
        'schedule': crontab(hour=2, minute=50),
        'args': ()
    },
}

这是问题所在:

如果任务在下一个任务的计划时间之前完成,则可以正常工作。但是如果一个任务运行了很长时间,比如说task1运行了两个小时,那么后面的任务就会每次执行几次。如果我重新启动 celery 和 celerybeat,有时它仍然有超时任务,但有时没有。

这让我很困惑。我已经阅读了一段时间的 celery 文档,但不知道为什么。谁能告诉我为什么会发生这种情况,如果任务队列被阻塞或芹菜重新启动,芹菜如何管理其消息和任务?

4

1 回答 1

0

在 settings.py 添加更多配置

'''
Task hard time limit in seconds.
The worker processing the task will be killed and replaced with a new one when this is exceeded.
'''
CELERYD_TASK_TIME_LIMIT = 86400
# CELERYD_TASK_TIME_LIMIT = 10
'''
Task soft time limit in seconds.
The SoftTimeLimitExceeded exception will be raised when this is exceeded. The task can catch this to e.g.
clean up before the hard time limit comes.
'''
CELERYD_TASK_SOFT_TIME_LIMIT = 80000
于 2016-04-08T04:02:23.523 回答