Debian Codegraph @

third_party/python/taskcluster_taskgraph/taskgraph/actions/cancel.py

raw
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/.
4
5
6 import logging
7
8 import requests
9
10 from taskgraph.util.taskcluster import cancel_task
11
12 from .registry import register_callback_action
13
14 logger = logging.getLogger(__name__)
15
16
17 @register_callback_action(
18 title="Cancel Task",
19 name="cancel",
20 symbol="cx",
21 description=("Cancel the given task"),
22 order=350,
23 context=[{}],
24 )
25 def cancel_action(parameters, graph_config, input, task_group_id, task_id):
26 # Note that this is limited by the scopes afforded to generic actions to
27 # only cancel tasks with the level-specific schedulerId.
28 try:
29 cancel_task(task_id, use_proxy=True)
30 except requests.HTTPError as e:
31 if e.response.status_code == 409:
32 # A 409 response indicates that this task is past its deadline. It
33 # cannot be cancelled at this time, but it's also not running
34 # anymore, so we can ignore this error.
35 logger.info(
36 f'Task "{task_id}" is past its deadline and cannot be cancelled.'
37 )
38 return
39 raise