Skip to content

Commit bac778e

Browse files
committed
rename runwise .history files as .closed
1 parent b049e4c commit bac778e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/osa/scripts/gain_selection.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def update_history_file(run_id: str, subrun: str, log_dir: Path, history_file: P
337337
return
338338

339339
elif job_status.item() == "COMPLETED":
340-
log.info(f"Job {job_id} finished successfully, updating history file.")
340+
log.debug(f"Job {job_id} finished successfully, updating history file.")
341341
string_to_write = (
342342
f"{run_id:05d}.{subrun:04d} gain_selection 0\n"
343343
)
@@ -359,6 +359,14 @@ def is_run_already_copied(date: datetime, run_id: int) -> bool:
359359
return len(r0_files)==len(r0g_files)
360360

361361

362+
def is_closed(date: datetime, run_id: str) -> bool:
363+
"""Check if run is already closed."""
364+
base_dir = Path(cfg.get("LST1", "BASE"))
365+
log_dir = base_dir / f"R0G/log/{date_to_dir(date)}"
366+
closed_run_file = log_dir / f"gain_selection_{run_id:05d}.closed"
367+
return closed_run_file.exists()
368+
369+
362370
def GainSel_flag_file(date: datetime) -> Path:
363371
"""Return the path to the file indicating the completion of the gain selection stage."""
364372
filename = cfg.get("LSTOSA", "gain_selection_check")
@@ -401,9 +409,9 @@ def check_gainsel_jobs_runwise(date: datetime, run_id: int) -> bool:
401409
log.warning(f"{date_to_iso(date)}: Some gain selection jobs did not finish successfully for run {run_id}")
402410
return False
403411
else:
404-
log.info(f"{date_to_iso(date)}: All jobs finished successfully for run {run_id}, creating the corresponding history file")
405-
run_history_file = log_dir / f"gain_selection_{run_id:05d}.history"
406-
run_history_file.touch()
412+
log.info(f"{date_to_iso(date)}: All jobs finished successfully for run {run_id}, creating the corresponding .closed file")
413+
closed_run_file = log_dir / f"gain_selection_{run_id:05d}.closed"
414+
closed_run_file.touch()
407415
return True
408416

409417

@@ -434,10 +442,10 @@ def check_failed_jobs(date: datetime):
434442
for run in data_runs:
435443
run_id = run["run_id"]
436444
check_warnings_in_logs(date, run_id)
437-
438-
if not check_gainsel_jobs_runwise(date, run_id):
439-
log.warning(f"Gain selection did not finish successfully for run {run_id}.")
440-
failed_runs.append(run)
445+
if not is_closed(date, run_id):
446+
if not check_gainsel_jobs_runwise(date, run_id):
447+
log.warning(f"Gain selection did not finish successfully for run {run_id}.")
448+
failed_runs.append(run)
441449

442450
if failed_runs:
443451
log.warning(f"Gain selection did not finish successfully for {date_to_iso(date)}, cannot create the flag file.")

0 commit comments

Comments
 (0)