使用相同的args/kwarg撤消芹菜任务 [英] Revoke celery tasks with same args/kwargs

查看:32
本文介绍了使用相同的args/kwarg撤消芹菜任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,如果要执行长时间的任务,并且要有一组特定的args和kwargs.在启动新任务之前,是否有机会以相同的args/kwargs撤销所有正在运行和待处理的任务,因为Im只对最后添加的任务的结果感兴趣.(底层数据在两次调用之间发生变化)

Imagine having a long running task with a specific set of args and kwargs. Is there any chance to revoke all running and pending tasks with the same args/kwargs before starting a new task as Im only interested in the result of the last added task. (The underlying data changes inbetween two calls)

我尝试迭代 inspect.active() inspect.registered() inspect.scheduled()的结果以获取全部任务,然后 filter/revoke 那些带有我的args和kwargs的任务.

I tried iterating the results of inspect.active(), inspect.registered() and inspect.scheduled() to get ALL tasks and then filter/revoke those with my args and kwargs in question.

但这并不可靠,因为检查所有工人和寻找任务的时间太长了.

But this was not reliable as the inspecting of all workers and searching for tasks took way too long.

任何人都可以使我朝正确的方向前进吗?

Anyone can get me in the right direction?

推荐答案

如果检查工作人员速度较慢,则最好通过辅助数据存储(例如像redis这样的键值存储)进行检查.您为功能添加了一个锁",因此您知道它已经启动了.

If inspecting the workers is to slow, it might be better to check via a secondary data storage, for example a key-value store like redis. You add an "lock" for an function, so you know you already started it.

排队任务时:

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