Compare commits

..

2 commits

Author SHA1 Message Date
Rob Ede
f6ba95c070
feat: migrate server to actix-http 2024-05-26 22:22:06 +01:00
Rob Ede
ebec04d2de
refactor: migrate to tracing for logging 2024-05-26 21:42:38 +01:00
4 changed files with 13 additions and 19 deletions

8
Cargo.lock generated
View file

@ -538,12 +538,6 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "error_reporter"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31ae425815400e5ed474178a7a22e275a9687086a12ca63ec793ff292d8fdae8"
[[package]] [[package]]
name = "faster-hex" name = "faster-hex"
version = "0.9.0" version = "0.9.0"
@ -2703,7 +2697,6 @@ dependencies = [
"crates-index", "crates-index",
"derive_more", "derive_more",
"dotenvy", "dotenvy",
"error_reporter",
"font-awesome-as-a-crate", "font-awesome-as-a-crate",
"futures-util", "futures-util",
"gix", "gix",
@ -2712,7 +2705,6 @@ dependencies = [
"lru_time_cache", "lru_time_cache",
"maud", "maud",
"once_cell", "once_cell",
"parking_lot",
"pulldown-cmark", "pulldown-cmark",
"relative-path", "relative-path",
"reqwest", "reqwest",

View file

@ -24,12 +24,10 @@ derive_more = "0.99"
dotenvy = "0.15" dotenvy = "0.15"
font-awesome-as-a-crate = "0.3" font-awesome-as-a-crate = "0.3"
futures-util = { version = "0.3", default-features = false, features = ["std"] } futures-util = { version = "0.3", default-features = false, features = ["std"] }
error_reporter = "1"
indexmap = { version = "2", features = ["serde"] } indexmap = { version = "2", features = ["serde"] }
lru_time_cache = "0.11" lru_time_cache = "0.11"
maud = "0.26" maud = "0.26"
once_cell = "1" once_cell = "1"
parking_lot = "0.12"
pulldown-cmark = "0.11" pulldown-cmark = "0.11"
relative-path = { version = "1", features = ["serde"] } relative-path = { version = "1", features = ["serde"] }
reqwest = { version = "0.12", features = ["json"] } reqwest = { version = "0.12", features = ["json"] }

View file

@ -56,7 +56,7 @@ fn init_tracing_subscriber() {
.init(); .init();
} }
#[tokio::main(flavor = "current_thread")] #[tokio::main]
async fn main() { async fn main() {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
init_tracing_subscriber(); init_tracing_subscriber();
@ -98,9 +98,10 @@ async fn main() {
.client_request_timeout(Duration::from_secs(5)) .client_request_timeout(Duration::from_secs(5))
.finish(move |req: Request| { .finish(move |req: Request| {
let app = app.clone(); let app = app.clone();
let path = req.path().to_owned();
async move { async move {
let path = req.path().to_owned();
app.handle(req) app.handle(req)
.instrument(tracing::info_span!("@", %path)) .instrument(tracing::info_span!("@", %path))
.await .await

View file

@ -26,7 +26,9 @@ impl ManagedIndex {
} }
pub fn crate_(&self, crate_name: CrateName) -> Option<Crate> { pub fn crate_(&self, crate_name: CrateName) -> Option<Crate> {
self.index.lock().unwrap().crate_(crate_name.as_ref()) let index = self.index.lock().unwrap();
index.crate_(crate_name.as_ref())
} }
pub async fn refresh_at_interval(&self, update_interval: Duration) { pub async fn refresh_at_interval(&self, update_interval: Duration) {
@ -36,21 +38,22 @@ impl ManagedIndex {
loop { loop {
if let Err(err) = self.refresh().await { if let Err(err) = self.refresh().await {
tracing::error!( tracing::error!(
"failed refreshing the crates.io-index, the operation will be retried: {}", "failed refreshing the crates.io-index, the operation will be retried: {err}"
error_reporter::Report::new(err),
); );
} }
update_interval.tick().await; update_interval.tick().await;
} }
} }
async fn refresh(&self) -> Result<(), crates_index::Error> { async fn refresh(&self) -> Result<()> {
let index = Arc::clone(&self.index); let index = Arc::clone(&self.index);
spawn_blocking(move || index.lock().unwrap().update()) spawn_blocking(move || {
.await let mut index = index.lock().unwrap();
.expect("blocking index update task should never panic")?;
index.update()
})
.await??;
Ok(()) Ok(())
} }
} }