Skip to content

Commit 685a897

Browse files
Merge pull request #722 from Mark-Simulacrum/current-collection-ui
Show last collection end time
2 parents f469ef7 + f535f74 commit 685a897

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-8
lines changed

database/src/pool.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{ArtifactId, ArtifactIdNumber};
22
use crate::{Cache, CollectionId, Index, Profile, QueryDatum, QueuedCommit, Step};
3+
use chrono::{DateTime, Utc};
34
use hashbrown::HashMap;
45
use std::sync::{Arc, Mutex};
56
use std::time::Duration;
@@ -74,6 +75,8 @@ pub trait Connection: Send + Sync {
7475
async fn in_progress_artifacts(&self) -> Vec<ArtifactId>;
7576

7677
async fn in_progress_steps(&self, aid: &ArtifactId) -> Vec<Step>;
78+
79+
async fn last_end_time(&self) -> Option<DateTime<Utc>>;
7780
}
7881

7982
#[async_trait::async_trait]

database/src/pool/postgres.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ impl PostgresConnection {
372372
(select end_time - start_time
373373
from collector_progress as cp
374374
where
375-
cp.step = collector_progress.step
375+
cp.aid != $1
376+
and cp.step = collector_progress.step
376377
and cp.start_time is not null
377378
and cp.end_time is not null
378379
order by start_time desc
@@ -932,4 +933,17 @@ where
932933
})
933934
.collect()
934935
}
936+
async fn last_end_time(&self) -> Option<DateTime<Utc>> {
937+
self.conn()
938+
.query_opt(
939+
"select date_recorded + (duration || 'seconds')::interval \
940+
from artifact_collection_duration \
941+
order by date_recorded desc \
942+
limit 1;",
943+
&[],
944+
)
945+
.await
946+
.unwrap()
947+
.map(|r| r.get(0))
948+
}
935949
}

database/src/pool/sqlite.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{ArtifactId, CollectionId, Commit, Crate, Date, Profile};
33
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
4-
use chrono::{TimeZone, Utc};
4+
use chrono::{DateTime, TimeZone, Utc};
55
use hashbrown::HashMap;
66
use rusqlite::params;
77
use rusqlite::OptionalExtension;
@@ -754,4 +754,17 @@ impl Connection for SqliteConnection {
754754
.map(|r| r.unwrap())
755755
.collect()
756756
}
757+
async fn last_end_time(&self) -> Option<DateTime<Utc>> {
758+
self.raw_ref()
759+
.query_row(
760+
"select date_recorded + duration \
761+
from artifact_collection_duration \
762+
order by date_recorded desc \
763+
limit 1;",
764+
params![],
765+
|r| Ok(Utc.timestamp(r.get(0)?, 0)),
766+
)
767+
.optional()
768+
.unwrap()
769+
}
757770
}

site/src/api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ pub mod status {
194194
pub benchmarks: Vec<BenchmarkStatus>,
195195
pub missing: Vec<(Commit, MissingReason)>,
196196
pub current: Option<CurrentState>,
197+
// None if no recent end, otherwise seconds since epoch
198+
pub most_recent_end: Option<i64>,
197199
}
198200
}
199201

site/src/server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ pub async fn handle_status_page(data: Arc<InputData>) -> status::Response {
307307
benchmarks: benchmark_state,
308308
missing,
309309
current,
310+
most_recent_end: conn.last_end_time().await.map(|d| d.timestamp()),
310311
}
311312
}
312313

site/static/status.html

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div>&gt; <a href="index.html">graphs</a>, <a href="compare.html">compare</a>,
2020
<a href="dashboard.html">dashboard</a>, <a href="status.html">status</a>.</div>
2121
<div id="data">
22-
<div id="missing-commits"></div>
22+
<div id="data-insert-js"></div>
2323
Benchmarks for last commit:
2424
<div id="benchmark-state"></div>
2525
</div>
@@ -32,7 +32,7 @@
3232

3333
function populate_data(data) {
3434
let state_div = document.querySelector("#benchmark-state");
35-
{
35+
if (data.last_commit) {
3636
let element = document.createElement("p");
3737
element.innerHTML = `SHA: ${data.last_commit.sha}, date: ${data.last_commit.date}`;
3838
state_div.appendChild(element);
@@ -54,7 +54,7 @@
5454
}
5555
state_div.appendChild(element);
5656
}
57-
let missing_div = document.querySelector("#missing-commits");
57+
let missing_div = document.querySelector("#data-insert-js");
5858
if (data.current !== null) {
5959
let table = document.createElement("table");
6060
let tr = document.createElement("tr");
@@ -87,9 +87,11 @@
8787
td = document.createElement("td");
8888
td.innerHTML = step.current_progress == 0 ? "" :
8989
format_duration(step.current_progress);
90+
td.style.textAlign = "right";
9091
tr.appendChild(td);
9192
td = document.createElement("td");
9293
td.innerHTML = format_duration(step.expected_duration);
94+
td.style.textAlign = "right";
9395
tr.appendChild(td);
9496
if (!step.is_done) {
9597
left += step.expected_duration - step.current_progress;
@@ -109,7 +111,14 @@
109111
missing_div.appendChild(table);
110112
} else {
111113
let element = document.createElement("p");
112-
element.innerHTML = `(Current work is not currently displayed; this is being worked on)`;
114+
if (data.most_recent_end) {
115+
let end = new Date(data.most_recent_end * 1000);
116+
element.innerHTML = `No current collection in progress. Last one
117+
finished at ${end.toLocaleString()} local time,
118+
${format_duration(Math.trunc((new Date() - end)/1000))} ago.`;
119+
} else {
120+
element.innerHTML = "No current collection in progress.";
121+
}
113122
missing_div.appendChild(element);
114123
}
115124
{
@@ -118,6 +127,7 @@
118127
missing_div.appendChild(element);
119128
}
120129
let table = document.createElement("table");
130+
table.id = "missing-commits";
121131
{
122132
let row = document.createElement("tr");
123133
row.innerHTML = `<th>Commit Date</th><th>SHA</th><th>Reason</th>`;
@@ -161,9 +171,11 @@
161171
let hours = Math.trunc(mins / 60);
162172
mins -= hours*60;
163173

164-
let s = `${mins < 10 ? "&nbsp;" + mins : mins}m${secs < 10 ? "0" + secs : secs}s`;
174+
let s = "";
165175
if (hours > 0) {
166-
s = `${hours}h ${s}`;
176+
s = `${hours}h${mins < 10 ? "0" + mins : mins}m${secs < 10 ? "0" + secs : secs}s`;
177+
} else {
178+
s = `${mins < 10 ? " " + mins : mins}m${secs < 10 ? "0" + secs : secs}s`;
167179
}
168180
return s;
169181
}

0 commit comments

Comments
 (0)