From 0c9da27bf0e628cfc53d281e8c1b181bad0bea8e Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 24 Jun 2023 20:27:36 -0700 Subject: do not crash rendering index page containing restarted jobs --- src/main.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 862e021..bdbad85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -315,9 +315,22 @@ async fn handle_ci_index(State(ctx): State>) -> impl IntoResponse { let last_build_time = Utc.timestamp_millis_opt(job.created_time as i64).unwrap().to_rfc2822(); let duration = if let Some(start_time) = job.start_time { if let Some(complete_time) = job.complete_time { - let duration_ms = complete_time - start_time; - let duration = duration_as_human_string(duration_ms); - duration + if complete_time < start_time { + if job.state == JobState::Started { + // this job has been restarted. the completed time is stale. + // further, this is a currently active job. + let now_ms = SystemTime::now().duration_since(UNIX_EPOCH).expect("now is after then").as_millis() as u64; + let mut duration = duration_as_human_string(now_ms - start_time); + duration.push_str(" (ongoing)"); + duration + } else { + "invalid data".to_string() + } + } else { + let duration_ms = complete_time - start_time; + let duration = duration_as_human_string(duration_ms); + duration + } } else { let now_ms = SystemTime::now().duration_since(UNIX_EPOCH).expect("now is after then").as_millis() as u64; let mut duration = duration_as_human_string(now_ms - start_time); -- cgit v1.1