Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check state of the jobs launched by autocloser #269

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/osa/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,33 @@
return sacct_output


def get_closer_sacct_output(sacct_output) -> pd.DataFrame:
"""
Fetch the information of jobs in the queue launched by AUTOCLOSER using the sacct
SLURM output and store it in a pandas dataframe.

Returns
-------
queue_list: pd.DataFrame
"""
sacct_output = pd.read_csv(sacct_output, names=FORMAT_SLURM)

# Keep only the jobs corresponding to AUTOCLOSER sequences
sacct_output = sacct_output[
(sacct_output["JobName"].str.contains("lstchain"))
morcuended marked this conversation as resolved.
Show resolved Hide resolved
| (sacct_output["JobName"].str.contains("provproces"))
]

try:
sacct_output["JobID"] = sacct_output["JobID"].apply(lambda x: x.split("_")[0])
sacct_output["JobID"] = sacct_output["JobID"].str.strip(".batch").astype(int)

except AttributeError:
log.debug("No job info could be obtained from sacct")

Check warning on line 727 in src/osa/job.py

View check run for this annotation

Codecov / codecov/patch

src/osa/job.py#L726-L727

Added lines #L726 - L727 were not covered by tests

return sacct_output


def filter_jobs(job_info: pd.DataFrame, sequence_list: Iterable):
"""Filter the job info list to get the values of the jobs in the current queue."""
sequences_info = pd.DataFrame([vars(seq) for seq in sequence_list])
Expand Down
32 changes: 31 additions & 1 deletion src/osa/scripts/closer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@
import shutil
import subprocess
import sys
import time
from datetime import datetime, timedelta
from pathlib import Path
from typing import Tuple, Iterable, List

from osa import osadb
from osa.configs import options
from osa.configs.config import cfg
from osa.job import are_all_jobs_correctly_finished, save_job_information
from osa.job import (
are_all_jobs_correctly_finished,
save_job_information,
run_sacct,
get_closer_sacct_output
)
from osa.nightsummary.extract import extract_runs, extract_sequences
from osa.nightsummary.nightsummary import run_summary_table
from osa.paths import destination_dir
Expand Down Expand Up @@ -169,6 +175,20 @@
if not options.no_dl2:
merge_files(seq_list, data_level="DL2")

time.sleep(300)

# Check if all jobs launched by autocloser finished correctly
# before creating the NightFinished.txt file
n_max = 10
n = 0
while not all_closer_jobs_finished_correctly() & n <= n_max:
morcuended marked this conversation as resolved.
Show resolved Hide resolved
log.info(

Check warning on line 185 in src/osa/scripts/closer.py

View check run for this annotation

Codecov / codecov/patch

src/osa/scripts/closer.py#L185

Added line #L185 was not covered by tests
"All jobs launched by autocloser did not finished correctly yet. "
"Checking again in 5 minutes..."
)
time.sleep(300)
n += 1

Check warning on line 190 in src/osa/scripts/closer.py

View check run for this annotation

Codecov / codecov/patch

src/osa/scripts/closer.py#L189-L190

Added lines #L189 - L190 were not covered by tests

if options.seqtoclose is None:
database = cfg.get("database", "path")
if database:
Expand Down Expand Up @@ -490,5 +510,15 @@
log.debug("Simulate launching scripts")


def all_closer_jobs_finished_correctly():
"""Check if all the jobs launched by autocloser finished correctly."""
sacct_output = run_sacct()
jobs_closer = get_closer_sacct_output(sacct_output)
if len(jobs_closer[jobs_closer["State"]!="COMPLETED"])==0:
return True
else:
return False

Check warning on line 520 in src/osa/scripts/closer.py

View check run for this annotation

Codecov / codecov/patch

src/osa/scripts/closer.py#L520

Added line #L520 was not covered by tests


if __name__ == "__main__":
main()