【问题标题】:Removing all Celery results from a Redis backend从 Redis 后端删除所有 Celery 结果
【发布时间】:2019-08-29 14:32:41
【问题描述】:

Celery 中是否有任何方法可以通过命令行删除所有以前的任务结果?我能找到的所有内容都参考purge,但这似乎不适用于任务结果。我发现的其他解决方案包括使用 Celery beat 定期删除它,但我正在寻找一次性命令行解决方案。

我使用 Celery 4.3.0。

【问题讨论】:

    标签: django redis celery


    【解决方案1】:

    所以基于这个答案:How do I delete everything in Redis?

    使用 redis-cli:

    FLUSHDB - Removes data from your connection's CURRENT database.
    FLUSHALL - Removes data from ALL databases.
    

    Redis 文档:

    flushdb
    flushall
    

    例如,在你的 shell 中:

    redis-cli 刷新

    并尝试清除芹菜。 来自 celery 文档:http://docs.celeryproject.org/en/latest/faq.html?highlight=purge#how-do-i-purge-all-waiting-tasks

    【讨论】:

    • 这会像上面所说的那样删除所有内容,这是个糟糕的建议。 OP 只想删除任务结果。
    【解决方案2】:

    我认为这就是你要找的东西:

    https://github.com/celery/celery/issues/4656

    参考

    https://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-result_expires

    我是这样设置的:

    RESULT_EXPIRE_TIME = 60 * 60 * 4  # keep tasks around for four hours
    
    ...
    
    celery = celery.Celery('tasks',
                           broker=Config.BROKER_URL,
                           backend=Config.CELERY_RESULTS_BACKEND,
                           include=['tasks.definitions'],
                           result_expires=RESULT_EXPIRE_TIME)
    

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 2017-05-28
      • 2018-09-11
      • 2012-01-15
      • 2017-04-10
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 2017-03-30
      相关资源
      最近更新 更多