Skip to content

Commit

Permalink
Add an API function for reporting run summary
Browse files Browse the repository at this point in the history
The distinction between a high-level API function and a driver was
rather blurred for the driver function responsible for printing out the
run summary.  Hence, I moved out the content of the driver to a separate
function, report(), and made the driver call it instead.
  • Loading branch information
mxk62 committed Jun 8, 2021
1 parent 2ef3bfa commit 72cd638
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
26 changes: 2 additions & 24 deletions python/lsst/ctrl/bps/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import time

from lsst.obs.base import Instrument
from lsst.utils import doImport

from . import BpsConfig
from .bps_draw import draw_networkx_dot
Expand All @@ -45,7 +44,7 @@
from .prepare import prepare
from .submit import BPS_SEARCH_ORDER, submit
from .cancel import cancel
from .report import print_headers, print_run, print_single_run_summary
from .report import report


_LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -224,28 +223,7 @@ def report_driver(wms_service, user, run_id, hist_days, pass_thru):
pass_thru : `str`
A string to pass directly to the WMS service class.
"""
wms_service_class = doImport(wms_service)
wms_service = wms_service_class({})

# If reporting on single run, increase history until better mechanism
# for handling completed jobs is available.
if run_id:
hist_days = max(hist_days, 2)

runs, message = wms_service.report(run_id, user, hist_days, pass_thru)

if run_id:
if not runs:
print(f"No information found for id='{run_id}'.")
print(f"Double check id and retry with a larger --hist value"
f"(currently: {hist_days})")
for run in runs:
print_single_run_summary(run)
else:
print_headers()
for run in sorted(runs, key=lambda j: j.wms_id):
print_run(run)
print(message)
report(wms_service, user, run_id, hist_days, pass_thru)


def cancel_driver(wms_service, run_id, user, require_bps, pass_thru):
Expand Down
42 changes: 42 additions & 0 deletions python/lsst/ctrl/bps/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import logging

from lsst.utils import doImport

from .wms_service import WmsStates


Expand All @@ -36,6 +38,46 @@
_LOG = logging.getLogger(__name__)


def report(wms_service, user, run_id, hist_days, pass_thru):
"""Print out summary of jobs submitted for execution.
Parameters
----------
wms_service : `str`
Name of the class.
user : `str`
A user name the report will be restricted to.
run_id : `str`
A run id the report will be restricted to.
hist_days : int
Number of days
pass_thru : `str`
A string to pass directly to the WMS service class.
"""
wms_service_class = doImport(wms_service)
wms_service = wms_service_class({})

# If reporting on single run, increase history until better mechanism
# for handling completed jobs is available.
if run_id:
hist_days = max(hist_days, 2)

runs, message = wms_service.report(run_id, user, hist_days, pass_thru)

if run_id:
if not runs:
print(f"No information found for id='{run_id}'.")
print(f"Double check id and retry with a larger --hist value"
f"(currently: {hist_days})")
for run in runs:
print_single_run_summary(run)
else:
print_headers()
for run in sorted(runs, key=lambda j: j.wms_id):
print_run(run)
print(message)


def print_headers():
"""Print headers.
"""
Expand Down

0 comments on commit 72cd638

Please sign in to comment.