芹菜击败旧的(删除)任务

时间:2016-09-08 18:53:33

标签: django celery supervisor celery-task celerybeat

supervisor下,celery beat为芹菜工作者提供定期任务以获取我的Django应用程序。我有4个任务,task1task2task3task4。最近我做了第5项任务:task5

我的问题是我从工人那里评论了task5,从settings.py中删除了它的提及,然后重新启动了celerybeat和我的芹菜工人。但我仍然看到task5定期出现(自然地在工人日志中抛出错误)。

为什么会发生这种情况,如何更新定期任务?

在settings.py中,我有:

    import djcelery
    djcelery.setup_loader()
    # config settings for Celery Daemon

    # Redis broker
    BROKER_URL = 'redis://localhost:6379/0'

    BROKER_TRANSPORT = 'redis'

    # List of modules to import when celery starts, in myapp.tasks form. 
    CELERY_IMPORTS = ('myapp.tasks', )  

    CELERY_ALWAYS_EAGER = False

    CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
    #The backend is the resource which returns the results of a completed task from Celery. 6379 is the default port to the redis server.

    CELERY_ACCEPT_CONTENT = ['json']
    CELERY_TASK_SERIALIZER = 'json'
    CELERY_RESULT_SERIALIZER = 'json'
    CELERY_IGNORE_RESULT=True

    from datetime import timedelta

    CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'

    CELERYBEAT_SCHEDULE = {
        'tasks.task1': {
            'task': 'tasks.task1',
            'schedule': timedelta(seconds=45),
        },
        'tasks.task2': {
            'task': 'tasks.task2',
            'schedule': timedelta(seconds=60),  # execute every 60 seconds
            'args': (),
        },
        'tasks.task3': {
            'task': 'tasks.task3',
            'schedule': timedelta(seconds=90),  # execute every 90 seconds
            'args': (),
        },
        'tasks.task4': {
            'task': 'tasks.task4',
            'schedule': timedelta(seconds=90),  # execute every 90 seconds
            'args': (),
        },
    }

/etc/supervisor/conf.d/celerybeat.conf包含以下内容:

command=python manage.py celery beat -l info
directory = /home/myuser/myproject/
environment=PATH="/home/myuser/envs/myenv/bin",VIRTUAL_ENV="/home/myuser/envs/myenv",PYTHONPATH="/home/myuser/envs/myenv/lib/python2.7:/home/myuser/envs/myenv/lib/python2.7/site-packages"
user=mhb11
numprocs=1
stdout_logfile = /etc/supervisor/logs/celerybeat.log
stderr_logfile = /etc/supervisor/logs/celerybeat.log
autostart = true
autorestart = true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=999

如果您需要,请向我询问更多信息。提前谢谢。

2 个答案:

答案 0 :(得分:1)

我相信你已经在队列中有待处理的任务。

您需要purge them。或者,如果你知道他们的id(注意,除非你覆盖它,任务id是唯一生成的......这些不是任务的名称),你也可以revoke them

答案 1 :(得分:1)

另一个可能的原因是您正在使用

"parsedquery_toString": "+(((brand:amul brand:cheese brand:cake)~2)^10.0 | 
((description_synonyms:amul description_synonyms:cheese (description_synonyms:cupcak description_synonyms:pastri description_synonyms:\"plum cake\" description_synonyms:cake))~2)^4.0 | 
((tags:amul tags:cheese tags:cake)~2))~1.0"

您的任务已存储在您的数据库中,仅从CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler' 中删除它们就不会将其删除。

您需要删除或禁用不需要的定期任务(如果已启用,则可以通过管理员上的djcelery应用轻松完成)

https://docs.celeryproject.org/en/stable/userguide/configuration.html#std:setting-beat_scheduler