Skip to content

Commit 2ab323c

Browse files
committed
options
1 parent feb26be commit 2ab323c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pyhdtoolkit/scripts/htc_monitor.py

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

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

3030
from pyhdtoolkit.utils.htcondor import _make_cluster_table, _make_tasks_table, query_condor_q, read_condor_q
3131
from pyhdtoolkit.utils.logging import config_logger
@@ -36,7 +36,7 @@
3636

3737
# ----- CLI App ----- #
3838

39-
app: typer.Typer = typer.Typer(help="A script to monitor HTCondor queue status.")
39+
app: Typer = Typer(help="A script to monitor HTCondor queue status.")
4040

4141
# ----- Bread and Butter ----- #
4242

@@ -87,22 +87,25 @@ def generate_renderable() -> Group:
8787

8888
@app.command()
8989
def main(
90-
log_level: str = typer.Option(
91-
"ERROR", help="Console logging level. Can be 'DEBUG', 'INFO', 'WARNING' and 'ERROR'."
92-
),
90+
wait: int = Option(300, "-w", "--wait", help="Seconds to wait between calls to `condor_q`."),
91+
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'."),
9393
):
9494
"""
9595
Parse the HTCondor queue and display
9696
the status in a nice way using `rich`.
9797
"""
98+
# Configure our logger and level (only for functions, not rich Console)
9899
config_logger(level=log_level)
99100

100-
with Live(generate_renderable(), refresh_per_second=0.25) as live:
101+
# Directly use Live to update the display. The display build itself
102+
# is defined in the function above and takes care of the query etc.
103+
with Live(generate_renderable(), refresh_per_second=refresh) as live:
101104
live.console.log("Querying HTCondor Queue - Refreshed Every 5 Minutes\n")
102105
while True:
103106
try:
104107
live.update(generate_renderable())
105-
time.sleep(300)
108+
time.sleep(wait)
106109
except KeyboardInterrupt:
107110
live.console.log("Exiting Program")
108111
break

0 commit comments

Comments
 (0)