2018-06-27 18:01:40 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
|
2019-04-30 22:16:12 +03:00
|
|
|
import logging
|
|
|
|
import requests
|
|
|
|
|
2018-06-27 18:01:40 +03:00
|
|
|
from taskgraph.util.taskcluster import cancel_task
|
|
|
|
from .registry import register_callback_action
|
|
|
|
|
2019-04-30 22:16:12 +03:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2018-06-27 18:01:40 +03:00
|
|
|
|
|
|
|
@register_callback_action(
|
|
|
|
title="Cancel Task",
|
|
|
|
name="cancel",
|
|
|
|
symbol="cx",
|
|
|
|
description=("Cancel the given task"),
|
2018-07-06 23:28:23 +03:00
|
|
|
order=350,
|
2018-06-27 18:01:40 +03:00
|
|
|
context=[{}],
|
|
|
|
)
|
2019-02-11 23:27:33 +03:00
|
|
|
def cancel_action(parameters, graph_config, input, task_group_id, task_id):
|
2018-06-27 18:01:40 +03:00
|
|
|
# Note that this is limited by the scopes afforded to generic actions to
|
|
|
|
# only cancel tasks with the level-specific schedulerId.
|
2019-04-30 22:16:12 +03:00
|
|
|
try:
|
|
|
|
cancel_task(task_id, use_proxy=True)
|
|
|
|
except requests.HTTPError as e:
|
|
|
|
if e.response.status_code == 409:
|
|
|
|
# A 409 response indicates that this task is past its deadline. It
|
|
|
|
# cannot be cancelled at this time, but it's also not running
|
|
|
|
# anymore, so we can ignore this error.
|
2021-08-24 22:35:46 +03:00
|
|
|
logger.info(f"Task {task_id} is past its deadline and cannot be cancelled.")
|
2019-04-30 22:16:12 +03:00
|
|
|
return
|
|
|
|
raise
|