From 5cbbcecab7117e70133bfadd2a86b5571ecdac8f Mon Sep 17 00:00:00 2001 From: Benjamin Tovar Date: Thu, 22 Jan 2026 12:04:59 -0500 Subject: [PATCH] vine: cancel all by tag cancel all the tasks (but recovery tasks) with the given tag --- .../python3/ndcctools/taskvine/manager.py | 10 ++++++ taskvine/src/manager/taskvine.h | 8 +++++ taskvine/src/manager/vine_manager.c | 35 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/taskvine/src/bindings/python3/ndcctools/taskvine/manager.py b/taskvine/src/bindings/python3/ndcctools/taskvine/manager.py index a26946be1e..522f2fc28f 100644 --- a/taskvine/src/bindings/python3/ndcctools/taskvine/manager.py +++ b/taskvine/src/bindings/python3/ndcctools/taskvine/manager.py @@ -749,6 +749,16 @@ def cancel_by_task_id(self, id): def cancel_by_task_tag(self, tag): return cvine.vine_cancel_by_task_tag(self._taskvine, tag) + ## + # Cancel all tasks with the given tag. + # The cancelled tasks will be returned in the normal way via @ref wait with a result of VINE_RESULT_CANCELLED. + # + # @param self Reference to the current manager object. + # @param tag The tag assigned to tasks using @ref ndcctools.taskvine.task.Task.set_tag. + # @return The total number of tasks cancelled. + def cancel_all_by_tag(self, tag): + return cvine.vine_cancel_all_by_tag(self._taskvine, tag) + ## # Cancel all tasks of the given category. # The cancelled tasks will be returned in the normal way via @ref wait with a result of VINE_RESULT_CANCELLED. diff --git a/taskvine/src/manager/taskvine.h b/taskvine/src/manager/taskvine.h index bc3f2f7ac8..a0cf9995a4 100644 --- a/taskvine/src/manager/taskvine.h +++ b/taskvine/src/manager/taskvine.h @@ -1332,6 +1332,14 @@ The cancelled task will be returned in the normal way via @ref vine_wait with a */ int vine_cancel_by_task_tag(struct vine_manager *m, const char *tag); +/** Cancel all submitted tasks with the given tag and remove them from the manager. +Each cancelled task will be returned in the normal way via @ref vine_wait with a result of VINE_RESULT_CANCELLED. +@param m A manager object +@param tag The tag name assigned to tasks using @ref vine_task_set_tag. +@return The number of tasks cancelled. +*/ +int vine_cancel_all_by_tag(struct vine_manager *m, const char *tag); + /** Cancel all submitted tasks and remove them from the manager. Each cancelled task will be returned in the normal way via @ref vine_wait with a result of VINE_RESULT_CANCELLED. @param m A manager object diff --git a/taskvine/src/manager/vine_manager.c b/taskvine/src/manager/vine_manager.c index 66a672b835..91022dceb7 100644 --- a/taskvine/src/manager/vine_manager.c +++ b/taskvine/src/manager/vine_manager.c @@ -5671,6 +5671,41 @@ int vine_cancel_by_task_tag(struct vine_manager *q, const char *task_tag) } } +int vine_cancel_all_by_tag(struct vine_manager *q, const char *tag) +{ + int count = 0; + struct vine_task *t; + uint64_t task_id; + + ITABLE_ITERATE(q->tasks, task_id, t) + { + switch (t->state) { + case VINE_TASK_RETRIEVED: + case VINE_TASK_DONE: + /* these tasks are already in a final state, so we can skip them */ + continue; + default: + switch (t->type) { + case VINE_TASK_TYPE_STANDARD: + case VINE_TASK_TYPE_LIBRARY_INSTANCE: + if (task_tag_comparator(t, tag)) { + vine_cancel_by_task_id(q, task_id); + count++; + } + break; + case VINE_TASK_TYPE_RECOVERY: + case VINE_TASK_TYPE_LIBRARY_TEMPLATE: + /* recovery tasks should not be canceled (unless explicitely by task id) + * as there are temporary files that the workflow already considers done. */ + continue; + break; + } + } + } + + return count; +} + int vine_cancel_all(struct vine_manager *q) { int count = 0;