Skip to content

Commit 03f79e7

Browse files
committed
Include active jobs in history, and sort by start time
1 parent 4311b05 commit 03f79e7

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

common/src/jobs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ impl JobStatus {
258258
}
259259
}
260260

261+
pub fn time_started(&self) -> DateTime<Utc> {
262+
match self {
263+
Self::Started { time_started, .. } | Self::Ended { time_started, .. } => *time_started,
264+
}
265+
}
266+
261267
pub fn time_elapsed(&self) -> TimeDelta {
262268
match self {
263269
Self::Started { time_started, .. } => Utc::now() - time_started,

server/src/manager.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,19 @@ impl JobManager {
428428
&self,
429429
_authn: &Identity, // anyone may retrieve job history
430430
) -> Result<Vec<JobStatus>, JobError> {
431-
Ok(self
432-
.job_history
433-
.lock()
434-
.await
435-
.iter()
436-
.map(|(_id, status)| status.to_owned())
437-
.collect())
431+
let mut jobs = Vec::new();
432+
self.with_jobs(
433+
&mut self.session.lock().await,
434+
|active_jobs, job_history| {
435+
for (_id, status) in active_jobs.iter().chain(job_history.iter()) {
436+
jobs.push(status.clone());
437+
}
438+
Ok(())
439+
},
440+
)
441+
.await?;
442+
jobs.sort_by_key(JobStatus::time_started);
443+
Ok(jobs)
438444
}
439445

440446
pub async fn job_start(

0 commit comments

Comments
 (0)