Skip to content

Commit e555212

Browse files
committed
batchtools with less output for class purposes. tests must be updated but for now, quick fix
1 parent c2bd1b0 commit e555212

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

batchtools/br.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
import sys
88
import time
99
import uuid
10+
import subprocess
1011

1112
import openshift_client as oc
1213

1314
from .basecommand import Command
1415
from .basecommand import SubParserFactory
1516
from .build_yaml import build_job_body
16-
from .helpers import pretty_print
1717
from .helpers import oc_delete
1818
from .helpers import fmt
1919
from .file_setup import prepare_context
@@ -175,9 +175,9 @@ def run(args: argparse.Namespace):
175175
getlist_path=getlist,
176176
)
177177

178-
print(f"Creating job {job_name} in {queue_name}...")
178+
# print(f"Creating job {job_name} in {queue_name}...")
179179
oc.create(job_body)
180-
print(f"Job {job_name} created successfully.")
180+
# print(f"Job {job_name} created successfully.")
181181

182182
result_phase = "unknown"
183183
run_elapsed = None
@@ -229,6 +229,7 @@ def run(args: argparse.Namespace):
229229
sys.exit(f"Error occurred while creating job: {e}")
230230

231231
if args.job_delete and args.wait:
232+
subprocess.run(["cat", f"jobs/{job_name}.log"], check=True)
232233
print(f"RUNDIR: jobs/{job_name}")
233234
oc_delete("job", job_name)
234235
else:
@@ -257,7 +258,7 @@ def log_job_output(
257258
"""
258259
pods = oc.selector("pod", labels={"job-name": job_name}).objects()
259260
if not pods:
260-
print(f"No pods found for job {job_name}")
261+
# print(f"No pods found for job {job_name}")
261262
return ("unknown", None, None, None)
262263

263264
pod = pods[0]
@@ -280,7 +281,7 @@ def log_job_output(
280281
if phase in ("Succeeded", "Failed"):
281282
result_phase = phase.lower()
282283
total_wall = time.monotonic() - start_poll # submit -> terminal
283-
print(f"Pod {pod_name} finished with phase={phase}")
284+
# print(f"Pod {pod_name} finished with phase={phase}")
284285
break
285286

286287
if timeout and (time.monotonic() - start_poll) > timeout:
@@ -290,12 +291,12 @@ def log_job_output(
290291
oc_delete("job", job_name)
291292
total_wall = time.monotonic() - start_poll
292293
# timeout: no run duration (didn't finish), queue_wait may or may not be set
293-
print_timing(queue_wait, None, total_wall)
294+
# print_timing(queue_wait, None, total_wall)
294295
return ("timeout", None, queue_wait, total_wall)
295296

296297
time.sleep(2)
297298

298-
print(pretty_print(pod))
299+
# print(pretty_print(pod))
299300

300301
# compute the runtime using the total time (total_wall)- time waiting in queue (queue_wait)
301302

@@ -312,18 +313,18 @@ def log_job_output(
312313
if total_wall is not None and queue_wait is None:
313314
queue_wait = total_wall
314315

315-
print_timing(queue_wait, run_elapsed, total_wall)
316+
# print_timing(queue_wait, run_elapsed, total_wall)
316317
return (result_phase, run_elapsed, queue_wait, total_wall)
317318

318319

319-
def print_timing(
320-
queue_wait: Optional[float],
321-
run_elapsed: Optional[float],
322-
total_wall: Optional[float],
323-
) -> None:
324-
print(
325-
"TIMING: "
326-
f"queue_wait={fmt(queue_wait)}, "
327-
f"run_duration={fmt(run_elapsed)}, "
328-
f"total_wall={fmt(total_wall)}"
329-
)
320+
# def print_timing(
321+
# queue_wait: Optional[float],
322+
# run_elapsed: Optional[float],
323+
# total_wall: Optional[float],
324+
# ) -> None:
325+
# print(
326+
# "TIMING: "
327+
# f"queue_wait={fmt(queue_wait)}, "
328+
# f"run_duration={fmt(run_elapsed)}, "
329+
# f"total_wall={fmt(total_wall)}"
330+
# )

batchtools/build_yaml.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
2626
oc rsh {devpod_name} rm -f \
2727
{jobs_dir}/{job_name}/getlist
28-
2928
"""
3029

3130

batchtools/helpers.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ def is_on_project() -> bool:
1919
return False
2020

2121

22-
def pretty_print(pod: oc.APIObject) -> str:
23-
formatted_logs: str = ""
24-
try:
25-
logs: dict[str, str] = pod.logs()
26-
# ⋆ ˚。⋆୨୧˚ stringify and pretty print for readibility ⋆ ˚。⋆୨୧˚
27-
formatted_logs = str(logs).replace("\\n", "\n")
28-
except oc.OpenShiftPythonException as e:
29-
print(f"Error occurred while retrieving logs: {e}")
30-
31-
return formatted_logs
22+
# def pretty_print(pod: oc.APIObject) -> str:
23+
# formatted_logs: str = ""
24+
# try:
25+
# logs: dict[str, str] = pod.logs()
26+
# # ⋆ ˚。⋆୨୧˚ stringify and pretty print for readibility ⋆ ˚。⋆୨୧˚
27+
# formatted_logs = str(logs).replace("\\n", "\n")
28+
# except oc.OpenShiftPythonException as e:
29+
# print(f"Error occurred while retrieving logs: {e}")
30+
# return formatted_logs
3231

3332

3433
def oc_delete(obj_type: str, obj_name: str) -> None:
3534
try:
36-
print(f"Deleting {obj_type}/{obj_name}")
35+
# print(f"Deleting {obj_type}/{obj_name}")
3736
oc.selector(f"{obj_type}/{obj_name}").delete()
3837
except oc.OpenShiftPythonException as e:
3938
print(f"Error occurred while deleting {obj_type}/{obj_name}: {e}")

batchtools/prom_metrics.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def push_registry_text(grouping_key: dict[str, str] | None = None) -> None:
154154
registry=registry,
155155
grouping_key=grouping_key or {},
156156
)
157-
print(f"PROM: metrics pushed to pushgateway={PUSHGATEWAY_ADDR}")
157+
# print(f"PROM: metrics pushed to pushgateway={PUSHGATEWAY_ADDR}")
158158
except Exception as e:
159-
print(f"PROM: failed to push metrics to pushgateway {PUSHGATEWAY_ADDR}: {e}")
159+
pass
160+
# print(f"PROM: failed to push metrics to pushgateway {PUSHGATEWAY_ADDR}: {e}")

0 commit comments

Comments
 (0)