Skip to content

Commit 1a5f4bf

Browse files
committed
viewer2: Show git hash and uptime
1 parent d8bf72d commit 1a5f4bf

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

viewer2/Cargo.lock

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

viewer2/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "archivebot-viewer"
33
version = "0.0.0"
44
edition = "2021"
55
publish = false
6+
rust-version = "1.80"
67

78
[dependencies]
89
anyhow = "1.0.71"
@@ -12,6 +13,7 @@ axum = "0.7.5"
1213
chrono = { version = "0.4.26", features = ["serde"] }
1314
clap = { version = "4.3.5", features = ["derive"] }
1415
futures = "0.3.28"
16+
git-version = "0.3.9"
1517
idna = "1.0.2"
1618
lazy_static = "1.4.0"
1719
percent-encoding = "2.3.0"

viewer2/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ mod database;
33
mod ia;
44
mod web;
55

6-
use std::{fmt::Display, net::IpAddr, path::PathBuf, process::ExitCode, time::Duration};
6+
use std::{fmt::Display, net::IpAddr, path::PathBuf, process::ExitCode, sync::LazyLock, time::{Duration, Instant}};
77

88
use clap::Parser;
99
use tokio_util::sync::CancellationToken;
1010
use tracing::Level;
1111
use tracing_subscriber::prelude::*;
1212

13+
static START_TIME: LazyLock<Instant> = LazyLock::new(Instant::now);
14+
1315
#[derive(Parser, Debug)]
1416
#[command(author, version)]
1517
struct Args {
@@ -78,6 +80,8 @@ async fn main() -> ExitCode {
7880
}
7981

8082
async fn main_inner() -> anyhow::Result<()> {
83+
let _ = *START_TIME;
84+
8185
let args = Args::parse();
8286

8387
init_logging();

viewer2/src/web.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use chrono::{DateTime, Datelike, NaiveDate, Utc};
1111
use serde::Deserialize;
1212
use tokio::net::TcpListener;
1313

14-
use crate::backend::{
15-
AuditItem, Backend, CostRow, DomainRow, ItemRow, JobRow, JobsRow, SearchResult,
14+
use crate::{
15+
backend::{AuditItem, Backend, CostRow, DomainRow, ItemRow, JobRow, JobsRow, SearchResult},
16+
START_TIME,
1617
};
1718

1819
const PAGE_LIMIT: i64 = 1000;
@@ -130,6 +131,8 @@ struct IndexTemplate {
130131
query: String,
131132
search_results: Vec<SearchResult>,
132133
last_update: DateTime<Utc>,
134+
git_hash: &'static str,
135+
uptime: (u32, u8, u8, u8), // (days, hours, minutes, seconds)
133136
}
134137

135138
async fn index_handler(
@@ -146,11 +149,19 @@ async fn index_handler(
146149
};
147150
let last_update = state.backend.get_last_update().await?;
148151

152+
let uptime = START_TIME.elapsed();
153+
let uptime_sec = (uptime.as_secs() % 60) as u8;
154+
let uptime_min = (uptime.as_secs() / 60 % 60) as u8;
155+
let uptime_hour = (uptime.as_secs() / 3600 % 60) as u8;
156+
let uptime_day = (uptime.as_secs() / 86400) as u32;
157+
149158
Ok(IndexTemplate {
150159
link_prefix: state.link_prefix,
151160
query: search_params.q,
152161
search_results,
153162
last_update,
163+
git_hash: git_version::git_version!(fallback = "unknown"),
164+
uptime: (uptime_day, uptime_hour, uptime_min, uptime_sec),
154165
})
155166
}
156167

viewer2/templates/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,12 @@
3838
<a href="{{ link_prefix }}stats">Stats</a> &ndash; graphs of resource usage on Internet Archive<br>
3939

4040
<p>Last update: {{ last_update }}</p>
41+
<details>
42+
<summary>Debug info</summary>
43+
<ul>
44+
<li>Git commit hash: {{ git_hash }}</li>
45+
<li>Executable uptime: {{ uptime.0 }}d {{ uptime.1 }}h {{ uptime.2 }}m {{ uptime.3 }}s</li>
46+
</ul>
47+
</details>
4148
<p>Attention: Please <a href="{{ link_prefix }}faq">read this</a> to learn how this index works.</p>
4249
{% endblock %}

0 commit comments

Comments
 (0)