如何按任务名称检查和取消Celery任务 [英] How to inspect and cancel Celery tasks by task name

查看:90
本文介绍了如何按任务名称检查和取消Celery任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Redis作为经纪人使用Celery(3.0.15)。

I'm using Celery (3.0.15) with Redis as a broker.

有没有一种直接的方法来查询具有给定名称的任务数

Is there a straightforward way to query the number of tasks with a given name that exist in a Celery queue?

并且作为后续操作,是否可以取消存在于Celery队列中的所有具有给定名称的任务?

And, as a followup, is there a way to cancel all tasks with a given name that exist in a Celery queue?

我已经通过监视和管理指南 ,在那儿看不到解决方案。

I've been through the Monitoring and Management Guide and don't see a solution there.

推荐答案

# Retrieve tasks
# Reference: http://docs.celeryproject.org/en/latest/reference/celery.events.state.html
query = celery.events.state.tasks_by_type(your_task_name)

# Kill tasks
# Reference: http://docs.celeryproject.org/en/latest/userguide/workers.html#revoking-tasks
for uuid, task in query:
    celery.control.revoke(uuid, terminate=True)

这篇关于如何按任务名称检查和取消Celery任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆