Skip to content

Commit 24e6090

Browse files
committed
no catching with logger, except more cases to handle
1 parent a108bea commit 24e6090

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

pyhdtoolkit/scripts/htc_monitor.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@
2121
import time
2222
from typing import TYPE_CHECKING
2323

24-
from loguru import logger
2524
from rich.console import Group
2625
from rich.live import Live
2726
from rich.panel import Panel
2827
from typer import Option, Typer
2928

30-
from pyhdtoolkit.utils.htcondor import _make_cluster_table, _make_tasks_table, query_condor_q, read_condor_q
29+
from pyhdtoolkit.utils.htcondor import (
30+
ClusterSummaryParseError,
31+
CondorQError,
32+
SchedulerInformationParseError,
33+
_make_cluster_table,
34+
_make_tasks_table,
35+
query_condor_q,
36+
read_condor_q,
37+
)
3138
from pyhdtoolkit.utils.logging import config_logger
3239

3340
if TYPE_CHECKING:
@@ -41,7 +48,6 @@
4148
# ----- Bread and Butter ----- #
4249

4350

44-
@logger.catch()
4551
def generate_renderable() -> Group:
4652
"""
4753
.. versionadded:: 0.9.0
@@ -89,7 +95,7 @@ def generate_renderable() -> Group:
8995
def main(
9096
wait: int = Option(300, "-w", "--wait", help="Seconds to wait between calls to `condor_q`."),
9197
refresh: float = Option(0.25, "-r", "--refresh", help="Display refreshes per second (higher means more CPU usage)."),
92-
log_level: str = Option("info", help="Console logging level. Can be 'DEBUG', 'INFO', 'WARNING' and 'ERROR'."),
98+
log_level: str = Option("warning", help="Console logging level. Can be 'DEBUG', 'INFO', 'WARNING' and 'ERROR'."),
9399
):
94100
"""
95101
Parse the HTCondor queue and display
@@ -101,14 +107,25 @@ def main(
101107
# Directly use Live to update the display. The display build itself
102108
# is defined in the function above and takes care of the query etc.
103109
with Live(generate_renderable(), refresh_per_second=refresh) as live:
104-
live.console.log("Querying HTCondor Queue - Refreshed Every 5 Minutes\n")
110+
live.console.log(f"Querying HTCondor Queue - Refreshed Every {wait:d} Seconds\n")
105111
while True:
106-
try:
112+
try: # query HTCondor queue, process, update display
107113
live.update(generate_renderable())
108114
time.sleep(wait)
115+
# In case the 'condor_q' command failed
116+
except CondorQError as err:
117+
live.console.log(f"[red]Error querying HTCondor:[/red]\n {err}")
118+
live.console.print_exception()
119+
break # exits
120+
# In case parsing the output of 'condor_q' failed
121+
except (ClusterSummaryParseError, SchedulerInformationParseError) as err:
122+
live.console.log(f"[red]Error parsing HTCondor output:[/red]\n {err}")
123+
live.console.print_exception()
124+
break # exits
125+
# Allow user to exit cleanly
109126
except KeyboardInterrupt:
110127
live.console.log("Exiting Program")
111-
break
128+
break # exits
112129

113130

114131
# ----- Script Mode ----- #

0 commit comments

Comments
 (0)