Last active
February 19, 2024 14:59
-
-
Save vuillaut/92ce2e400c38506ccbe0727e18d2d42f to your computer and use it in GitHub Desktop.
Analyse a `logs_reduced_*.yml` file from lstmcpipe by going through all job ids and printing their status if not COMPLETED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Analyse a `logs_reduced_*.yml` file from lstmcpipe by going through all job ids and printing their status if not COMPLETED | |
""" | |
import argparse | |
import yaml | |
import subprocess | |
import re | |
def get_data_from_yaml(file_path): | |
with open(file_path, 'r') as file: | |
data = yaml.safe_load(file) | |
return data | |
def job_status(job_id): | |
command = f"sacct -j {job_id} --format=State --noheader" | |
result = subprocess.run(command, shell=True, capture_output=True, text=True) | |
state = result.stdout.strip().split('\n')[0] # Take the first state result if multiple lines | |
return state | |
# Set up argparse to accept a filename | |
parser = argparse.ArgumentParser(description="Parse a YAML file, check integers as job IDs, and print their status.") | |
parser.add_argument("filename", type=str, help="The filename of the YAML file to parse.") | |
# Parse the arguments | |
args = parser.parse_args() | |
# Parse the YAML file and get the data | |
data = get_data_from_yaml(args.filename) | |
# Recursively check the data and print job status for integers | |
for stage, job_ids in data.items(): | |
stage_completed=True | |
for job_id, value in job_ids.items(): | |
state = job_status(job_id) | |
if "COMPLETED" not in state: | |
print(f"job {job_id} of stage {stage} is in state {state}") | |
stage_completed=False | |
if stage_completed: | |
print(f"STAGE {stage} completed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment