2018-06-27 18:01:40 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# 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/.
|
|
|
|
|
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
|
|
|
|
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(
|
2020-10-24 03:36:18 +03:00
|
|
|
title="Cancel Task",
|
|
|
|
name="cancel",
|
|
|
|
symbol="cx",
|
|
|
|
description=("Cancel the given task"),
|
2018-07-06 23:28:23 +03:00
|
|
|
order=350,
|
2020-10-24 03:36:18 +03:00
|
|
|
context=[{}],
|
2018-06-27 18:01:40 +03:00
|
|
|
)
|
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.
|
2020-10-24 03:36:18 +03:00
|
|
|
logger.info(
|
|
|
|
"Task {} is past its deadline and cannot be cancelled.".format(task_id)
|
2020-10-26 21:34:53 +03:00
|
|
|
)
|
2019-04-30 22:16:12 +03:00
|
|
|
return
|
|
|
|
raise
|