From 4d84ca3e158376714e1aba1665942c35cf184551 Mon Sep 17 00:00:00 2001 From: ric-evans Date: Wed, 29 Jan 2025 15:33:17 -0600 Subject: [PATCH] continue redefining what finished/completed scan is - wip --- skydriver/rest_handlers.py | 17 +++++++---------- skydriver/utils.py | 19 +++++++++++++------ tests/unit/test_scan_state.py | 13 +++++++------ 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/skydriver/rest_handlers.py b/skydriver/rest_handlers.py index e45d5f12..190c85a1 100644 --- a/skydriver/rest_handlers.py +++ b/skydriver/rest_handlers.py @@ -26,7 +26,7 @@ from tornado import web from wipac_dev_tools import argparse_tools -from . import database, ewms, images, k8s, utils +from . import database, ewms, images, k8s from .config import ( DEFAULT_K8S_CONTAINER_MEMORY_SKYSCAN_SERVER_BYTES, DEFAULT_MAX_WORKER_RUNTIME, @@ -741,11 +741,8 @@ async def delete(self, scan_id: str) -> None: # check DB states manifest = await self.manifests.get(scan_id, True) - if ( - manifest.progress - and manifest.progress.processing_stats.finished - and not args.delete_completed_scan - ): + _, scan_complete = await get_scan_state(manifest, self.ewms_rc, self.results) + if scan_complete: msg = "Attempted to delete a completed scan (must use `delete_completed_scan=True`)" raise web.HTTPError( 400, @@ -1049,7 +1046,9 @@ async def get(self, scan_id: str) -> None: LOGGER.exception(e) # scan state - scan_state = await get_scan_state(manifest, self.ewms_rc, self.results) + scan_state, scan_complete = await get_scan_state( + manifest, self.ewms_rc, self.results + ) # ewms if ( @@ -1066,9 +1065,7 @@ async def get(self, scan_id: str) -> None: resp = { "scan_state": scan_state, "is_deleted": manifest.is_deleted, - "scan_complete": bool( - scan_state == utils._ScanState.SCAN_FINISHED_SUCCESSFULLY.name - ), + "scan_complete": scan_complete, "pods": pods_411, "clusters": clusters, } diff --git a/skydriver/utils.py b/skydriver/utils.py index 7ba5a083..ec3900e1 100644 --- a/skydriver/utils.py +++ b/skydriver/utils.py @@ -18,6 +18,7 @@ class _ScanState(enum.Enum): IN_PROGRESS__PARTIAL_RESULT_GENERATED = enum.auto() IN_PROGRESS__WAITING_ON_FIRST_PIXEL_RECO = enum.auto() + PENDING__WAITING_ON_SCANNER_SERVER_STARTUP = enum.auto() PENDING__PRESTARTUP = enum.auto() @@ -26,11 +27,16 @@ async def get_scan_state( manifest: Manifest, ewms_rc: RestClient, results: database.interface.ResultClient, -) -> str: - """Determine the state of the scan by parsing attributes and talking with EWMS.""" +) -> tuple[str, bool]: + """Determine the state of the scan by parsing attributes and talking with EWMS. + + Returns tuple: + 1. the state as a human-readable string + 2. a bool for whether the scan was successful or not + """ if (await results.get(manifest.scan_id)).is_final: # NOTE: see note on 'SCAN_FINISHED_SUCCESSFULLY' above - return _ScanState.SCAN_FINISHED_SUCCESSFULLY.name + return _ScanState.SCAN_FINISHED_SUCCESSFULLY.name, True def _has_cleared_backlog() -> bool: return bool( @@ -73,11 +79,12 @@ def get_nonfinished_state() -> _ScanState: and isinstance(manifest.ewms_task, dict) and manifest.ewms_task.get("complete") ): - return f"STOPPED__{state.split('__')[1]}" # we didn't have info on what kind of stop + # we didn't have info on what kind of stop + return f"STOPPED__{state.split('__')[1]}", False # has EWMS ceased running the scan workers? elif dtype := await ewms.get_deactivated_type(ewms_rc, manifest.ewms_workflow_id): # -> yes, the ewms workflow has been deactivated - return f"{dtype.upper()}__{state.split('__')[1]}" + return f"{dtype.upper()}__{state.split('__')[1]}", False else: # -> no, this is a non-finished scan - return state + return state, False diff --git a/tests/unit/test_scan_state.py b/tests/unit/test_scan_state.py index 2c5b05a3..d38b445e 100644 --- a/tests/unit/test_scan_state.py +++ b/tests/unit/test_scan_state.py @@ -41,8 +41,9 @@ async def test_00__scan_finished_successfully( ), ) - assert ( - await get_scan_state(manifest, ewms_rc, results) == "SCAN_FINISHED_SUCCESSFULLY" + assert await get_scan_state(manifest, ewms_rc, results) == ( + "SCAN_FINISHED_SUCCESSFULLY", + True, ) @@ -82,7 +83,7 @@ async def test_10__partial_result_generated(ewms_dtype: str | None, state: str) ) with patch("skydriver.ewms.get_deactivated_type", return_value=ewms_dtype): - assert await get_scan_state(manifest, ewms_rc, results) == state + assert await get_scan_state(manifest, ewms_rc, results) == (state, False) @pytest.mark.parametrize( @@ -123,7 +124,7 @@ async def test_20__waiting_on_first_pixel_reco( ) with patch("skydriver.ewms.get_deactivated_type", return_value=ewms_dtype): - assert await get_scan_state(manifest, ewms_rc, results) == state + assert await get_scan_state(manifest, ewms_rc, results) == (state, False) @pytest.mark.parametrize( @@ -154,7 +155,7 @@ async def test_40__waiting_on_scanner_server_startup( ) with patch("skydriver.ewms.get_deactivated_type", return_value=ewms_dtype): - assert await get_scan_state(manifest, ewms_rc, results) == state + assert await get_scan_state(manifest, ewms_rc, results) == (state, False) @pytest.mark.parametrize( @@ -183,4 +184,4 @@ async def test_50__prestartup(ewms_dtype: str | None, state: str) -> None: ) with patch("skydriver.ewms.get_deactivated_type", return_value=ewms_dtype): - assert await get_scan_state(manifest, ewms_rc, results) == state + assert await get_scan_state(manifest, ewms_rc, results) == (state, False)