diff --git a/src/webmon_app/reporting/metrics/view_util.py b/src/webmon_app/reporting/metrics/view_util.py index b23c84fc..a571f7d3 100644 --- a/src/webmon_app/reporting/metrics/view_util.py +++ b/src/webmon_app/reporting/metrics/view_util.py @@ -8,6 +8,7 @@ def postprocessing_diagnostics(): + """collect and return Cataloging & Reduction diagnostics""" common_services = Instrument.objects.get(name="common") agents = [] @@ -42,7 +43,7 @@ def postprocessing_diagnostics(): def instrument_status(): - # return map of instrument name to run status + """return map of instrument name to run status""" instruments = Instrument.objects.all().order_by("name") status = {} @@ -57,18 +58,19 @@ def instrument_status(): def run_statuses(minutes=60): """Of all the runs created in the last n minutes, return the number that are acquiring, complete, incomplete, - error along with the total number""" + error or unknown along with the total number""" runs = DataRun.objects.filter(created_on__gte=timezone.now() - timezone.timedelta(minutes=minutes)).order_by( "created_on" ) - statuses = {"count": len(runs), "acquiring": 0, "incomplete": 0, "complete": 0, "error": 0} + statuses = {"total": len(runs), "acquiring": 0, "incomplete": 0, "complete": 0, "error": 0, "unknown": 0} for run_id in runs: try: s = WorkflowSummary.objects.get(run_id=run_id) except WorkflowSummary.DoesNotExist: + statuses["unknown"] += 1 continue if not is_acquisition_complete(run_id): diff --git a/src/webmon_app/reporting/tests/test_metrics/test_view_util.py b/src/webmon_app/reporting/tests/test_metrics/test_view_util.py index 1c518c96..cbb5d41f 100644 --- a/src/webmon_app/reporting/tests/test_metrics/test_view_util.py +++ b/src/webmon_app/reporting/tests/test_metrics/test_view_util.py @@ -127,11 +127,12 @@ def test_run_statuses(self): WorkflowSummary.objects.create(run_id=dataRun0, complete=True) statuses = run_statuses() - assert statuses["count"] == 0 + assert statuses["total"] == 0 assert statuses["acquiring"] == 0 assert statuses["incomplete"] == 0 assert statuses["complete"] == 0 assert statuses["error"] == 0 + assert statuses["unknown"] == 0 # run should be acquiring dataRun1 = DataRun(run_number=1, ipts_id=ipts, instrument_id=inst, file="/filename") @@ -139,11 +140,12 @@ def test_run_statuses(self): WorkflowSummary.objects.create(run_id=dataRun1) statuses = run_statuses() - assert statuses["count"] == 1 + assert statuses["total"] == 1 assert statuses["acquiring"] == 1 assert statuses["incomplete"] == 0 assert statuses["complete"] == 0 assert statuses["error"] == 0 + assert statuses["unknown"] == 0 # run should be incomplete dataRun2 = DataRun(run_number=2, ipts_id=ipts, instrument_id=inst, file="/filename") @@ -152,11 +154,12 @@ def test_run_statuses(self): WorkflowSummary.objects.create(run_id=dataRun2) statuses = run_statuses() - assert statuses["count"] == 2 + assert statuses["total"] == 2 assert statuses["acquiring"] == 1 assert statuses["incomplete"] == 1 assert statuses["complete"] == 0 assert statuses["error"] == 0 + assert statuses["unknown"] == 0 # run should be complete dataRun3 = DataRun(run_number=3, ipts_id=ipts, instrument_id=inst, file="/filename") @@ -165,11 +168,12 @@ def test_run_statuses(self): WorkflowSummary.objects.create(run_id=dataRun3, complete=True) statuses = run_statuses() - assert statuses["count"] == 3 + assert statuses["total"] == 3 assert statuses["acquiring"] == 1 assert statuses["incomplete"] == 1 assert statuses["complete"] == 1 assert statuses["error"] == 0 + assert statuses["unknown"] == 0 # run should be error dataRun4 = DataRun(run_number=4, ipts_id=ipts, instrument_id=inst, file="/filename") @@ -180,8 +184,21 @@ def test_run_statuses(self): WorkflowSummary.objects.create(run_id=dataRun4) statuses = run_statuses() - assert statuses["count"] == 4 + assert statuses["total"] == 4 assert statuses["acquiring"] == 1 assert statuses["incomplete"] == 1 assert statuses["complete"] == 1 assert statuses["error"] == 1 + assert statuses["unknown"] == 0 + + # create run but now WorkflowSummary. status should be unknown + dataRun5 = DataRun(run_number=5, ipts_id=ipts, instrument_id=inst, file="/filename") + dataRun5.save() + + statuses = run_statuses() + assert statuses["total"] == 5 + assert statuses["acquiring"] == 1 + assert statuses["incomplete"] == 1 + assert statuses["complete"] == 1 + assert statuses["error"] == 1 + assert statuses["unknown"] == 1