QTZPOC-20

QTZPOC-20: Refactor ModelImport status engine for lazy initialization, add byte-counted size validation to bundle extraction, optimize MLflow run ID lookups, and ensure workflow cancellation propagates correctly.
This commit is contained in:
2026-09-10 08:59:31 -03:00
parent d06ce0daae
commit 4c7cae502f
11 changed files with 452 additions and 119 deletions

View File

@@ -26,6 +26,7 @@ with workflow.unsafe.imports_passed_through():
from typing import Any
from sientia_do.temporal.policies import retry_policy
from temporalio.exceptions import is_cancelled_exception
from laborious.activities.activities import Activities
from laborious.activities.model_import import (
@@ -309,6 +310,8 @@ class ImportModel:
start_to_close_timeout=STATUS_WRITE_TIMEOUT,
)
except BaseException as error: # NOSONAR - a lost hint must not fail a working import
if is_cancelled_exception(error):
raise
await self._report_status_write_failure(base, error)
async def _record_terminal(
@@ -344,6 +347,8 @@ class ImportModel:
except (
BaseException
) as error: # NOSONAR - the outcome stands even when it cannot be written
if is_cancelled_exception(error):
raise
await self._report_status_write_failure(
base,
error,
@@ -377,8 +382,9 @@ class ImportModel:
retry_policy=IMPORT_STATUS_HINT_RETRY_POLICY,
start_to_close_timeout=STATUS_WRITE_TIMEOUT,
)
except BaseException: # noqa: S110 # NOSONAR - the report of a report is where this stops
pass
except BaseException as error: # NOSONAR - the report of a report is where this stops
if is_cancelled_exception(error):
raise
async def _report_status_write_failure(
self,
@@ -394,10 +400,12 @@ class ImportModel:
retry_policy=retry_policy,
start_to_close_timeout=STATUS_WRITE_TIMEOUT,
)
except BaseException: # noqa: S110 # NOSONAR - the report of a report is where this stops
# Deliberately silent: the channel this was trying to reach is the thing that logs, so
# there is nowhere left to say it, and an import that worked must not fail over it.
pass
except BaseException as error: # NOSONAR - the report of a report is where this stops
if is_cancelled_exception(error):
raise
# Deliberately silent otherwise: the channel this was trying to reach is the thing that
# logs, so there is nowhere left to say it, and an import that worked must not fail
# over it.
# ----------------------------------------------------------- side-effect steps
@@ -418,12 +426,13 @@ class ImportModel:
retry_policy=retry_policy,
start_to_close_timeout=RETENTION_TIMEOUT,
)
except BaseException: # noqa: S110 # NOSONAR - retention is not a precondition of an import
# Dropped, not reported: the activity's own failure is already in the event history,
# and a bucket policy the importer cannot set is an operational problem rather than a
# bad import. Failing a valid model import over a lifecycle API would be the wrong
# trade.
pass
except BaseException as error: # NOSONAR - retention is not a precondition of an import
if is_cancelled_exception(error):
raise
# Dropped, not reported otherwise: the activity's own failure is already in the event
# history, and a bucket policy the importer cannot set is an operational problem rather
# than a bad import. Failing a valid model import over a lifecycle API would be the
# wrong trade.
@staticmethod
async def _cleanup(base: dict[str, Any]) -> dict[str, Any]:
@@ -435,5 +444,7 @@ class ImportModel:
retry_policy=retry_policy,
start_to_close_timeout=CLEANUP_TIMEOUT,
)
except BaseException: # NOSONAR - cleanup never replaces the failure that brought us here
except BaseException as error: # NOSONAR - cleanup never replaces the failure that brought us here
if is_cancelled_exception(error):
raise
return {'cleaned': False}