Skip to content

Show last collection end time #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions database/src/pool.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{ArtifactId, ArtifactIdNumber};
use crate::{Cache, CollectionId, Index, Profile, QueryDatum, QueuedCommit, Step};
use chrono::{DateTime, Utc};
use hashbrown::HashMap;
use std::sync::{Arc, Mutex};
use std::time::Duration;
Expand Down Expand Up @@ -74,6 +75,8 @@ pub trait Connection: Send + Sync {
async fn in_progress_artifacts(&self) -> Vec<ArtifactId>;

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

async fn last_end_time(&self) -> Option<DateTime<Utc>>;
}

#[async_trait::async_trait]
Expand Down
16 changes: 15 additions & 1 deletion database/src/pool/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ impl PostgresConnection {
(select end_time - start_time
from collector_progress as cp
where
cp.step = collector_progress.step
cp.aid != $1
and cp.step = collector_progress.step
and cp.start_time is not null
and cp.end_time is not null
order by start_time desc
Expand Down Expand Up @@ -932,4 +933,17 @@ where
})
.collect()
}
async fn last_end_time(&self) -> Option<DateTime<Utc>> {
self.conn()
.query_opt(
"select date_recorded + (duration || 'seconds')::interval \
from artifact_collection_duration \
order by date_recorded desc \
limit 1;",
&[],
)
.await
.unwrap()
.map(|r| r.get(0))
}
}
15 changes: 14 additions & 1 deletion database/src/pool/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
use crate::{ArtifactId, CollectionId, Commit, Crate, Date, Profile};
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
use chrono::{TimeZone, Utc};
use chrono::{DateTime, TimeZone, Utc};
use hashbrown::HashMap;
use rusqlite::params;
use rusqlite::OptionalExtension;
Expand Down Expand Up @@ -754,4 +754,17 @@ impl Connection for SqliteConnection {
.map(|r| r.unwrap())
.collect()
}
async fn last_end_time(&self) -> Option<DateTime<Utc>> {
self.raw_ref()
.query_row(
"select date_recorded + duration \
from artifact_collection_duration \
order by date_recorded desc \
limit 1;",
params![],
|r| Ok(Utc.timestamp(r.get(0)?, 0)),
)
.optional()
.unwrap()
}
}
2 changes: 2 additions & 0 deletions site/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ pub mod status {
pub benchmarks: Vec<BenchmarkStatus>,
pub missing: Vec<(Commit, MissingReason)>,
pub current: Option<CurrentState>,
// None if no recent end, otherwise seconds since epoch
pub most_recent_end: Option<i64>,
}
}

Expand Down
1 change: 1 addition & 0 deletions site/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub async fn handle_status_page(data: Arc<InputData>) -> status::Response {
benchmarks: benchmark_state,
missing,
current,
most_recent_end: conn.last_end_time().await.map(|d| d.timestamp()),
}
}

Expand Down
24 changes: 18 additions & 6 deletions site/static/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div>&gt; <a href="index.html">graphs</a>, <a href="compare.html">compare</a>,
<a href="dashboard.html">dashboard</a>, <a href="status.html">status</a>.</div>
<div id="data">
<div id="missing-commits"></div>
<div id="data-insert-js"></div>
Benchmarks for last commit:
<div id="benchmark-state"></div>
</div>
Expand All @@ -32,7 +32,7 @@

function populate_data(data) {
let state_div = document.querySelector("#benchmark-state");
{
if (data.last_commit) {
let element = document.createElement("p");
element.innerHTML = `SHA: ${data.last_commit.sha}, date: ${data.last_commit.date}`;
state_div.appendChild(element);
Expand All @@ -54,7 +54,7 @@
}
state_div.appendChild(element);
}
let missing_div = document.querySelector("#missing-commits");
let missing_div = document.querySelector("#data-insert-js");
if (data.current !== null) {
let table = document.createElement("table");
let tr = document.createElement("tr");
Expand Down Expand Up @@ -87,9 +87,11 @@
td = document.createElement("td");
td.innerHTML = step.current_progress == 0 ? "" :
format_duration(step.current_progress);
td.style.textAlign = "right";
tr.appendChild(td);
td = document.createElement("td");
td.innerHTML = format_duration(step.expected_duration);
td.style.textAlign = "right";
tr.appendChild(td);
if (!step.is_done) {
left += step.expected_duration - step.current_progress;
Expand All @@ -109,7 +111,14 @@
missing_div.appendChild(table);
} else {
let element = document.createElement("p");
element.innerHTML = `(Current work is not currently displayed; this is being worked on)`;
if (data.most_recent_end) {
let end = new Date(data.most_recent_end * 1000);
element.innerHTML = `No current collection in progress. Last one
finished at ${end.toLocaleString()} local time,
${format_duration(Math.trunc((new Date() - end)/1000))} ago.`;
} else {
element.innerHTML = "No current collection in progress.";
}
missing_div.appendChild(element);
}
{
Expand All @@ -118,6 +127,7 @@
missing_div.appendChild(element);
}
let table = document.createElement("table");
table.id = "missing-commits";
{
let row = document.createElement("tr");
row.innerHTML = `<th>Commit Date</th><th>SHA</th><th>Reason</th>`;
Expand Down Expand Up @@ -161,9 +171,11 @@
let hours = Math.trunc(mins / 60);
mins -= hours*60;

let s = `${mins < 10 ? "&nbsp;" + mins : mins}m${secs < 10 ? "0" + secs : secs}s`;
let s = "";
if (hours > 0) {
s = `${hours}h ${s}`;
s = `${hours}h${mins < 10 ? "0" + mins : mins}m${secs < 10 ? "0" + secs : secs}s`;
} else {
s = `${mins < 10 ? " " + mins : mins}m${secs < 10 ? "0" + secs : secs}s`;
}
return s;
}
Expand Down