Skip to content

Commit

Permalink
Bug 1539631 - ignore 409 errors cancelling tasks; r=tomprince
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D28899

--HG--
extra : moz-landing-system : lando
  • Loading branch information
djmitche committed Apr 30, 2019
1 parent 846a148 commit 4a28520
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion taskcluster/taskgraph/actions/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@

from __future__ import absolute_import, print_function, unicode_literals

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',
Expand All @@ -24,4 +29,13 @@
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.
cancel_task(task_id, use_proxy=True)
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('Task is past its deadline and cannot be cancelled.'.format(task_id))
return
raise
13 changes: 12 additions & 1 deletion taskcluster/taskgraph/actions/cancel_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import concurrent.futures as futures
import logging
import os
import requests

from taskgraph.util.taskcluster import (
list_task_group_incomplete_tasks,
Expand All @@ -35,7 +36,17 @@
def cancel_all_action(parameters, graph_config, input, task_group_id, task_id):
def do_cancel_task(task_id):
logger.info('Cancelling task {}'.format(task_id))
cancel_task(task_id, use_proxy=True)
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(
'Task {} is past its deadline and cannot be cancelled.'.format(task_id))
return
raise

own_task_id = os.environ.get('TASK_ID', '')
to_cancel = [t for t in list_task_group_incomplete_tasks(task_group_id) if t != own_task_id]
Expand Down

0 comments on commit 4a28520

Please sign in to comment.