|
21 | 21 | import time |
22 | 22 | from typing import TYPE_CHECKING |
23 | 23 |
|
24 | | -import typer |
25 | 24 | from loguru import logger |
26 | 25 | from rich.console import Group |
27 | 26 | from rich.live import Live |
28 | 27 | from rich.panel import Panel |
| 28 | +from typer import Option, Typer |
29 | 29 |
|
30 | 30 | from pyhdtoolkit.utils.htcondor import _make_cluster_table, _make_tasks_table, query_condor_q, read_condor_q |
31 | 31 | from pyhdtoolkit.utils.logging import config_logger |
|
36 | 36 |
|
37 | 37 | # ----- CLI App ----- # |
38 | 38 |
|
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.") |
40 | 40 |
|
41 | 41 | # ----- Bread and Butter ----- # |
42 | 42 |
|
@@ -87,22 +87,25 @@ def generate_renderable() -> Group: |
87 | 87 |
|
88 | 88 | @app.command() |
89 | 89 | 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'."), |
93 | 93 | ): |
94 | 94 | """ |
95 | 95 | Parse the HTCondor queue and display |
96 | 96 | the status in a nice way using `rich`. |
97 | 97 | """ |
| 98 | + # Configure our logger and level (only for functions, not rich Console) |
98 | 99 | config_logger(level=log_level) |
99 | 100 |
|
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: |
101 | 104 | live.console.log("Querying HTCondor Queue - Refreshed Every 5 Minutes\n") |
102 | 105 | while True: |
103 | 106 | try: |
104 | 107 | live.update(generate_renderable()) |
105 | | - time.sleep(300) |
| 108 | + time.sleep(wait) |
106 | 109 | except KeyboardInterrupt: |
107 | 110 | live.console.log("Exiting Program") |
108 | 111 | break |
|
0 commit comments