File: cancel.py

package info (click to toggle)
thunderbird 1%3A144.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,725,312 kB
  • sloc: cpp: 7,869,225; javascript: 5,974,276; ansic: 3,946,747; python: 1,421,062; xml: 654,642; asm: 474,045; java: 183,117; sh: 110,973; makefile: 20,398; perl: 14,362; objc: 13,086; yacc: 4,583; pascal: 3,448; lex: 1,720; ruby: 999; exp: 762; sql: 731; awk: 580; php: 436; lisp: 430; sed: 69; csh: 10
file content (39 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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/.


import logging

import requests

from taskgraph.util.taskcluster import cancel_task

from .registry import register_callback_action

logger = logging.getLogger(__name__)


@register_callback_action(
    title="Cancel Task",
    name="cancel",
    symbol="cx",
    description=("Cancel the given task"),
    order=350,
    context=[{}],
)
def cancel_action(parameters, graph_config, input, task_group_id, task_id):
    # Note that this is limited by the scopes afforded to generic actions to
    # only cancel tasks with the level-specific schedulerId.
    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.
            logger.info(
                f'Task "{task_id}" is past its deadline and cannot be cancelled.'
            )
            return
        raise