summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2023-06-24 20:27:36 -0700
committeriximeow <me@iximeow.net>2023-06-24 20:27:36 -0700
commit0c9da27bf0e628cfc53d281e8c1b181bad0bea8e (patch)
treecc2bf45bc61a7a9879b522efdfac1e4573ac052b
parent916965ab13d4c9273089162a04d730f3061c6d18 (diff)
do not crash rendering index page containing restarted jobs
-rw-r--r--src/main.rs19
1 files changed, 16 insertions, 3 deletions
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<Arc<DbCtx>>) -> 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);