@@ -653,7 +653,7 @@ def get_squeue_output(squeue_output: StringIO) -> pd.DataFrame:
653
653
return df
654
654
655
655
656
- def run_sacct () -> StringIO :
656
+ def run_sacct (job_id : str = None ) -> StringIO :
657
657
"""Run sacct to obtain the job information."""
658
658
if shutil .which ("sacct" ) is None :
659
659
log .warning ("No job info available since sacct command is not available" )
@@ -668,13 +668,18 @@ def run_sacct() -> StringIO:
668
668
"-o" ,
669
669
"," .join (FORMAT_SLURM ),
670
670
]
671
+
672
+ if job_id :
673
+ sacct_cmd .append ("--jobs" )
674
+ sacct_cmd .append (job_id )
675
+
671
676
if cfg .get ("SLURM" , "STARTTIME_DAYS_SACCT" ):
672
677
days = int (cfg .get ("SLURM" , "STARTTIME_DAYS_SACCT" ))
673
678
start_date = (datetime .date .today () - datetime .timedelta (days = days )).isoformat ()
674
679
sacct_cmd .extend (["--starttime" , start_date ])
675
680
676
681
return StringIO (sp .check_output (sacct_cmd ).decode ())
677
-
682
+
678
683
679
684
def get_sacct_output (sacct_output : StringIO ) -> pd .DataFrame :
680
685
"""
@@ -809,3 +814,12 @@ def update_sequence_state(sequence, filtered_job_info: pd.DataFrame) -> None:
809
814
sequence .exit = "0:15"
810
815
elif any ("RUNNING" in job for job in filtered_job_info .State ):
811
816
sequence .state = "RUNNING"
817
+
818
+
819
+ def job_finished_in_timeout (job_id : str ) -> bool :
820
+ """Return True if the input job_id finished in TIMEOUT state."""
821
+ job_status = get_sacct_output (run_sacct (job_id = job_id ))["State" ]
822
+ if job_id and job_status .item () == "TIMEOUT" :
823
+ return True
824
+ else :
825
+ return False
0 commit comments