|
1 | | -# pyright: reportUninitializedInstanceVariable=false |
2 | 1 | from typing import cast |
3 | 2 | from typing_extensions import override, Optional |
4 | 3 |
|
@@ -185,10 +184,9 @@ def run(args: argparse.Namespace): |
185 | 184 | queue_wait = None |
186 | 185 | total_wall = None |
187 | 186 |
|
188 | | - if args.wait: |
189 | | - result_phase, run_elapsed, queue_wait, total_wall = log_job_output( |
190 | | - job_name=job_name, wait=True, timeout=args.timeout |
191 | | - ) |
| 187 | + result_phase, run_elapsed, queue_wait, total_wall = log_job_output( |
| 188 | + job_name=job_name, wait=True, timeout=args.timeout |
| 189 | + ) |
192 | 190 |
|
193 | 191 | if ( |
194 | 192 | run_elapsed is not None |
@@ -270,48 +268,48 @@ def log_job_output( |
270 | 268 | queue_wait = None |
271 | 269 | total_wall = None |
272 | 270 |
|
273 | | - if wait: |
274 | | - start_poll = time.monotonic() |
275 | | - while True: |
276 | | - phase = get_pod_status(pod_name) |
277 | | - if phase == "Running" and run_start is None: |
278 | | - # time waiting in queue is time from entering the queue to the time it takes to start running |
279 | | - run_start = time.monotonic() |
280 | | - queue_wait = run_start - start_poll # submit -> running |
281 | | - |
282 | | - if phase in ("Succeeded", "Failed"): |
283 | | - result_phase = phase.lower() |
284 | | - total_wall = time.monotonic() - start_poll # submit -> terminal |
285 | | - print(f"Pod {pod_name} finished with phase={phase}") |
286 | | - break |
287 | | - |
288 | | - if timeout and (time.monotonic() - start_poll) > timeout: |
| 271 | + start_poll = time.monotonic() |
| 272 | + while True: |
| 273 | + phase = get_pod_status(pod_name) |
| 274 | + if phase == "Running" and run_start is None: |
| 275 | + # time waiting in queue is time from entering the queue to the time it takes to start running |
| 276 | + run_start = time.monotonic() |
| 277 | + queue_wait = run_start - start_poll # submit -> running |
| 278 | + |
| 279 | + if phase in ("Succeeded", "Failed"): |
| 280 | + result_phase = phase.lower() |
| 281 | + total_wall = time.monotonic() - start_poll # submit -> terminal |
| 282 | + print(f"Pod {pod_name} finished with phase={phase}") |
| 283 | + break |
| 284 | + |
| 285 | + if timeout and (time.monotonic() - start_poll) > timeout: |
| 286 | + if wait: |
289 | 287 | print(f"Timeout waiting for pod {pod_name} to complete") |
290 | 288 | print(f"Deleting job {job_name}") |
291 | 289 | oc_delete("job", job_name) |
292 | | - total_wall = time.monotonic() - start_poll |
293 | | - # timeout: no run duration (didn't finish), queue_wait may or may not be set |
294 | | - print_timing(queue_wait, None, total_wall) |
295 | | - return ("timeout", None, queue_wait, total_wall) |
| 290 | + total_wall = time.monotonic() - start_poll |
| 291 | + # timeout: no run duration (didn't finish), queue_wait may or may not be set |
| 292 | + print_timing(queue_wait, None, total_wall) |
| 293 | + return ("timeout", None, queue_wait, total_wall) |
296 | 294 |
|
297 | | - time.sleep(2) |
| 295 | + time.sleep(2) |
298 | 296 |
|
299 | 297 | print(pretty_print(pod)) |
300 | 298 |
|
301 | 299 | # compute the runtime using the total time (total_wall)- time waiting in queue (queue_wait) |
302 | | - if wait: |
303 | | - if run_start is not None: |
304 | | - # running status was reached, run_elapsed = terminal - run_start |
305 | | - if total_wall is None: |
306 | | - total_wall = time.monotonic() - start_poll # fallback |
307 | | - run_elapsed = total_wall - (queue_wait or 0.0) |
308 | | - else: |
309 | | - # Never reached Running; keep convention for failures: |
310 | | - run_elapsed = 0.0 if result_phase == "failed" else None |
311 | | - if total_wall is None: |
312 | | - total_wall = 0.0 |
313 | | - if total_wall is not None and queue_wait is None: |
314 | | - queue_wait = total_wall |
| 300 | + |
| 301 | + if run_start is not None: |
| 302 | + # running status was reached, run_elapsed = terminal - run_start |
| 303 | + if total_wall is None: |
| 304 | + total_wall = time.monotonic() - start_poll # fallback |
| 305 | + run_elapsed = total_wall - (queue_wait or 0.0) |
| 306 | + else: |
| 307 | + # Never reached Running; keep convention for failures: |
| 308 | + run_elapsed = 0.0 if result_phase == "failed" else None |
| 309 | + if total_wall is None: |
| 310 | + total_wall = 0.0 |
| 311 | + if total_wall is not None and queue_wait is None: |
| 312 | + queue_wait = total_wall |
315 | 313 |
|
316 | 314 | print_timing(queue_wait, run_elapsed, total_wall) |
317 | 315 | return (result_phase, run_elapsed, queue_wait, total_wall) |
|
0 commit comments