Skip to content

Commit

Permalink
continue redefining what finished/completed scan is - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ric-evans committed Jan 29, 2025
1 parent 09bd9f9 commit 4d84ca3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
17 changes: 7 additions & 10 deletions skydriver/rest_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand All @@ -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,
}
Expand Down
19 changes: 13 additions & 6 deletions skydriver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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(
Expand Down Expand Up @@ -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
13 changes: 7 additions & 6 deletions tests/unit/test_scan_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)

0 comments on commit 4d84ca3

Please sign in to comment.