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