1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 import concurrent
.futures
as futures
11 from taskgraph
.util
.taskcluster
import CONCURRENCY
, cancel_task
13 from gecko_taskgraph
.util
.taskcluster
import list_task_group_incomplete_task_ids
15 from .registry
import register_callback_action
17 logger
= logging
.getLogger(__name__
)
20 @register_callback_action(
25 "Cancel all running and pending tasks created by the decision task "
26 "this action task is associated with."
31 def cancel_all_action(parameters
, graph_config
, input, task_group_id
, task_id
):
32 def do_cancel_task(task_id
):
33 logger
.info(f
"Cancelling task {task_id}")
35 cancel_task(task_id
, use_proxy
=True)
36 except requests
.HTTPError
as e
:
37 if e
.response
.status_code
== 409:
38 # A 409 response indicates that this task is past its deadline. It
39 # cannot be cancelled at this time, but it's also not running
40 # anymore, so we can ignore this error.
42 "Task {} is past its deadline and cannot be cancelled.".format(
49 own_task_id
= os
.environ
.get("TASK_ID", "")
52 for t
in list_task_group_incomplete_task_ids(task_group_id
)
56 logger
.info(f
"Cancelling {len(to_cancel)} tasks")
57 with futures
.ThreadPoolExecutor(CONCURRENCY
) as e
:
58 cancel_futs
= [e
.submit(do_cancel_task
, t
) for t
in to_cancel
]
59 for f
in futures
.as_completed(cancel_futs
):