diff --git a/maap_utils/JobLedger.py b/maap_utils/JobLedger.py index 0543a359195e8bd4cc5b29b0f65f58156d033aae..1b5cdd0a387a314007daf3ab67d71f234c95ea47 100644 --- a/maap_utils/JobLedger.py +++ b/maap_utils/JobLedger.py @@ -37,12 +37,19 @@ class JobLedger: def get_pending_jobs(self) -> List[Job]: """Get jobs not in final states""" - return [ + + # Get all unfinished jobs + pending = [ job for job_id, job in self.jobs.items() if self.status[job_id] not in self.FINAL_STATES ] + # Sort by last checked time, most recently checked last + pending.sort(key=lambda x: self.last_checked[x.job_id]) + + return pending + def get_finished_jobs(self) -> List[Job]: """Get only finished jobs""" return [