Skip to content

Commit 83a5a4c

Browse files
committed
Return both end_time and duration for the last recorded artifact collection
1 parent 49cca0e commit 83a5a4c

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

database/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,9 @@ pub struct CompileBenchmark {
668668
pub name: String,
669669
pub category: String,
670670
}
671+
672+
#[derive(Debug)]
673+
pub struct ArtifactCollection {
674+
pub duration: Duration,
675+
pub end_time: DateTime<Utc>,
676+
}

database/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{ArtifactId, ArtifactIdNumber, CompileBenchmark};
1+
use crate::{ArtifactCollection, ArtifactId, ArtifactIdNumber, CompileBenchmark};
22
use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step};
33
use chrono::{DateTime, Utc};
44
use hashbrown::HashMap;
@@ -153,7 +153,7 @@ pub trait Connection: Send + Sync {
153153

154154
async fn in_progress_steps(&self, aid: &ArtifactId) -> Vec<Step>;
155155

156-
async fn last_end_time(&self) -> Option<DateTime<Utc>>;
156+
async fn last_artifact_collection(&self) -> Option<ArtifactCollection>;
157157

158158
/// Returns the sha of the parent commit, if available.
159159
///

database/src/pool/postgres.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactId, ArtifactIdNumber, Benchmark, CollectionId, Commit, CommitType, CompileBenchmark,
4-
Date, Index, Profile, QueuedCommit, Scenario,
3+
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, CollectionId, Commit, CommitType,
4+
CompileBenchmark, Date, Index, Profile, QueuedCommit, Scenario,
55
};
66
use anyhow::Context as _;
77
use chrono::{DateTime, TimeZone, Utc};
@@ -1194,18 +1194,21 @@ where
11941194
})
11951195
.collect()
11961196
}
1197-
async fn last_end_time(&self) -> Option<DateTime<Utc>> {
1197+
async fn last_artifact_collection(&self) -> Option<ArtifactCollection> {
11981198
self.conn()
11991199
.query_opt(
1200-
"select date_recorded \
1200+
"select date_recorded, duration \
12011201
from artifact_collection_duration \
12021202
order by date_recorded desc \
12031203
limit 1;",
12041204
&[],
12051205
)
12061206
.await
12071207
.unwrap()
1208-
.map(|r| r.get(0))
1208+
.map(|r| ArtifactCollection {
1209+
end_time: r.get(0),
1210+
duration: Duration::from_secs(r.get::<_, i32>(1) as u64),
1211+
})
12091212
}
12101213
async fn parent_of(&self, sha: &str) -> Option<String> {
12111214
self.conn()

database/src/pool/sqlite.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactId, Benchmark, CollectionId, Commit, CommitType, CompileBenchmark, Date, Profile,
3+
ArtifactCollection, ArtifactId, Benchmark, CollectionId, Commit, CommitType, CompileBenchmark,
4+
Date, Profile,
45
};
56
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
67
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
@@ -1149,18 +1150,24 @@ impl Connection for SqliteConnection {
11491150
.collect()
11501151
}
11511152

1152-
async fn last_end_time(&self) -> Option<DateTime<Utc>> {
1153+
async fn last_artifact_collection(&self) -> Option<ArtifactCollection> {
11531154
self.raw_ref()
11541155
.query_row(
1155-
"select date_recorded + duration \
1156+
"select date_recorded + duration, duration \
11561157
from artifact_collection_duration \
11571158
order by date_recorded desc \
11581159
limit 1;",
11591160
params![],
1160-
|r| Ok(Utc.timestamp_opt(r.get(0)?, 0).unwrap()),
1161+
|r| {
1162+
Ok((
1163+
Utc.timestamp_opt(r.get(0)?, 0).unwrap(),
1164+
Duration::from_secs(r.get(1)?),
1165+
))
1166+
},
11611167
)
11621168
.optional()
11631169
.unwrap()
1170+
.map(|(end_time, duration)| ArtifactCollection { end_time, duration })
11641171
}
11651172

11661173
async fn parent_of(&self, sha: &str) -> Option<String> {

site/src/request_handlers/status_page.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ pub async fn handle_status_page(ctxt: Arc<SiteCtxt>) -> status::Response {
5454
benchmarks: benchmark_state,
5555
missing,
5656
current,
57-
most_recent_end: conn.last_end_time().await.map(|d| d.timestamp()),
57+
most_recent_end: conn
58+
.last_artifact_collection()
59+
.await
60+
.map(|d| d.end_time.timestamp()),
5861
}
5962
}
6063

0 commit comments

Comments
 (0)