Skip to content

Commit dd04299

Browse files
fix(tf): ignore conflicts when cancelling (#2843)
fix(tf): ignore conflicts when cancelling Do not log an error and and unsuccessful cancelling of the TF request when the job has already failed or finished successfully. Fixes #2830 Reviewed-by: gemini-code-assist[bot] Reviewed-by: Matej Focko Reviewed-by: Laura Barcziová
2 parents ee1c350 + 14ec7dd commit dd04299

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packit_service/worker/helpers/testing_farm_client.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import logging
55
import re
6+
from http import HTTPStatus
67
from re import Pattern
78
from typing import Any, Callable, Optional
89

@@ -103,13 +104,23 @@ def cancel(self, request_id: str) -> bool:
103104
endpoint=f"requests/{request_id}",
104105
method="DELETE",
105106
)
106-
if response.status_code not in (200, 204):
107-
# 200: successful test cancellation
108-
# 204: cancellation has already been requested, or even completed
107+
if response.status_code not in (HTTPStatus.OK, HTTPStatus.NO_CONTENT, HTTPStatus.CONFLICT):
108+
# OK:
109+
# successful test cancellation
110+
# NO_CONTENT:
111+
# cancellation has already been requested, or even completed
112+
# CONFLICT:
113+
# the request has already errored out or has finished
109114
msg = f"Failed to cancel TF request {request_id}: {response.json()}"
110115
logger.error(msg)
111116
return False
112117

118+
# [TODO] Reconsider implicit ‹True› instead of checking for status codes
119+
# Currently we set ‹cancel_requested› in the DB when returning ‹True›,
120+
# but it does not conform very well with suppressed CONFLICT (which is
121+
# returned when the test run has already errored out or has finished),
122+
# but it should be overriden by the webhook with test results from the
123+
# Testing Farm.
113124
return True
114125

115126
@classmethod

0 commit comments

Comments
 (0)