【问题标题】:celery: how to refresh scheduled task list after revoking?芹菜:撤销后如何刷新计划任务列表?
【发布时间】:2015-01-21 22:03:04
【问题描述】:

我使用以下代码撤销了所有任务。

from celery.task.control import inspect
from celery.task.control import revoke

i = inspect()
queues = i.scheduled()
keys = queues.keys()
all_tasks = []
tasks = []
if len(keys) > 0:
    print keys[0]
    all_tasks = queues[keys[0]]

for task in all_tasks:
    revoke(task['request']['id'], terminate=True)

但是 inspect().scheduled() 在我全部撤销之前返回相同的任务。 除了撤销之外,我如何获取任务列表?

【问题讨论】:

    标签: redis scheduled-tasks celery


    【解决方案1】:

    每个 async_result 对象都有 status 属性,它显示了任务的状态。因此,如果您有 all_tasks 的列表,则可以执行此操作。

    unrevoked_tasks = []
    for task in all_tasks:
        if task.status != 'REVOKED':
            unrevoked_tasks += task
    

    或者更好地使用这样的列表理解

    unrevoked_tasks = [task for task in all_tasks if task.status != 'REVOKED']
    

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 2016-02-21
      • 2019-12-09
      • 2015-09-28
      • 2015-05-25
      • 2014-08-05
      • 1970-01-01
      • 2014-09-22
      • 2012-08-30
      相关资源
      最近更新 更多