Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / taskcluster / gecko_taskgraph / actions / cancel_all.py
blobd74b83b7d81a163bbf35cd1a48db2201f69af3a5
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
7 import logging
8 import os
10 import requests
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(
21 title="Cancel All",
22 name="cancel-all",
23 symbol="cAll",
24 description=(
25 "Cancel all running and pending tasks created by the decision task "
26 "this action task is associated with."
28 order=400,
29 context=[],
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}")
34 try:
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.
41 logger.info(
42 "Task {} is past its deadline and cannot be cancelled.".format(
43 task_id
46 return
47 raise
49 own_task_id = os.environ.get("TASK_ID", "")
50 to_cancel = [
52 for t in list_task_group_incomplete_task_ids(task_group_id)
53 if t != own_task_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):
60 f.result()