Python 按名称删除芹菜任务(使用通配符?)

Python 按名称删除芹菜任务(使用通配符?),python,django,python-3.x,celery,Python,Django,Python 3.x,Celery,有没有办法从芹菜中删除一组特定的任务?也许用通配符?比如: app.control.delete("foobar-only-*") 我知道我可以使用删除所有任务 from proj.celery import app app.control.purge() 它来自,但这不是很有帮助,因为我似乎无法使用该代码来调整它并做我想做的事情。回答我自己的问题。这是我实现目标的代码摘录: def stop_crawler(crawler_name): crawler = Crawler.obje

有没有办法从芹菜中删除一组特定的任务?也许用通配符?比如:

app.control.delete("foobar-only-*")
我知道我可以使用删除所有任务

from proj.celery import app
app.control.purge()

它来自,但这不是很有帮助,因为我似乎无法使用该代码来调整它并做我想做的事情。

回答我自己的问题。这是我实现目标的代码摘录:

def stop_crawler(crawler_name):
    crawler = Crawler.objects.get(name=crawler_name)
    if crawler is None:
        logger.error(f"Can't find a crawler named {crawler_name}")
        return

    i = app.control.inspect()

    queue_name = f"collect_urls_{crawler_name}"

    # Iterate over all workers, and the queues of each worker, and stop workers
    # from consuming from the queue that belongs to the crawler we're stopping
    for worker_name, worker_queues in i.active_queues().items():
        for queue in worker_queues:
            if queue["name"] == queue_name:
                app.control.cancel_consumer(queue_name, reply=True)

    # Iterate over the different types of tasks and stop the ones that belong
    # to the crawler we're stopping
    for queue in [i.active, i.scheduled, i.reserved]:
        for worker_name, worker_tasks in queue().items():
            for task in worker_tasks:
                args = ast.literal_eval(task["args"])
                if "collect_urls" in task["name"] and args[0] == crawler_name:
                    app.control.revoke(task["id"], terminate=True)

可能取决于后端,因为这是特定于后端的,因为我不相信有任何方法,但
清除
如果您通过
app.control.revoke(task\u id,terminate=True)知道任务id,则可以终止任务。
它对您不起作用吗?