From 4fe206da65836fc683083fb9cc1ecff1a032c6b5 Mon Sep 17 00:00:00 2001 From: Eric Fahlgren Date: Fri, 24 Jan 2025 05:51:03 -0800 Subject: [PATCH] api: when specific build request failures occur attempt to recover If a build request has been received for a version, branch, target or subtarget that somehow has missed an update via webhooks, we invoke the 'update' mechanism and proceed with the error processing. The result is that this first build request still fails, but any future requests on the branch/target will (hopefully) succeed. Signed-off-by: Eric Fahlgren --- asu/routers/api.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/asu/routers/api.py b/asu/routers/api.py index 120eaf3b..41e03711 100644 --- a/asu/routers/api.py +++ b/asu/routers/api.py @@ -51,6 +51,18 @@ def validation_failure(detail: str) -> tuple[dict, int]: return {"detail": detail, "status": 400}, 400 +def _attempt_update(build_request: BuildRequest) -> None: + """If the profile has not been updated recently, we may be able to heal + things by forcing an update. + """ + get_queue().enqueue( + update, + version=build_request.version, + target_subtarget=build_request.target, + job_timeout="10m", + ) + + def validate_request(build_request: BuildRequest) -> tuple[dict, int]: """Validate an image request and return found errors with status code @@ -76,9 +88,11 @@ def validate_request(build_request: BuildRequest) -> tuple[dict, int]: r = get_redis_client() if not r.sismember("branches", branch): + _attempt_update(build_request) return validation_failure(f"Unsupported branch: {build_request.version}") if not r.sismember(f"versions:{branch}", build_request.version): + _attempt_update(build_request) return validation_failure(f"Unsupported version: {build_request.version}") build_request.packages: list[str] = [ @@ -89,6 +103,7 @@ def validate_request(build_request: BuildRequest) -> tuple[dict, int]: logging.debug(f"Profile before mapping {build_request.profile = }") if not r.hexists(f"targets:{branch}", build_request.target): + _attempt_update(build_request) return validation_failure(f"Unsupported target: {build_request.target}") sanitized_profile = build_request.profile.replace(",", "_") @@ -108,6 +123,7 @@ def validate_request(build_request: BuildRequest) -> tuple[dict, int]: logging.info(f"Use generic profile replacing {build_request.profile = }") build_request.profile = "generic" else: + _attempt_update(build_request) return validation_failure(f"Unsupported profile: {build_request.profile}") return ({}, None)