Compare commits

..

2 commits

Author SHA1 Message Date
Rob Ede
dfcdf31c72
feat: migrate server to actix-http 2024-05-27 06:58:29 +01:00
Rob Ede
85a077e80d
refactor: migrate to tracing for logging 2024-05-26 23:22:19 +01:00
4 changed files with 19 additions and 13 deletions

8
Cargo.lock generated
View file

@ -538,6 +538,12 @@ 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"
@ -2697,6 +2703,7 @@ 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",
@ -2705,6 +2712,7 @@ 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,10 +24,12 @@ 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] #[tokio::main(flavor = "current_thread")]
async fn main() { async fn main() {
dotenvy::dotenv().ok(); dotenvy::dotenv().ok();
init_tracing_subscriber(); init_tracing_subscriber();
@ -98,10 +98,9 @@ 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,9 +26,7 @@ impl ManagedIndex {
} }
pub fn crate_(&self, crate_name: CrateName) -> Option<Crate> { pub fn crate_(&self, crate_name: CrateName) -> Option<Crate> {
let index = self.index.lock().unwrap(); self.index.lock().unwrap().crate_(crate_name.as_ref())
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) {
@ -38,22 +36,21 @@ 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: {err}" "failed refreshing the crates.io-index, the operation will be retried: {}",
error_reporter::Report::new(err),
); );
} }
update_interval.tick().await; update_interval.tick().await;
} }
} }
async fn refresh(&self) -> Result<()> { async fn refresh(&self) -> Result<(), crates_index::Error> {
let index = Arc::clone(&self.index); let index = Arc::clone(&self.index);
spawn_blocking(move || { spawn_blocking(move || index.lock().unwrap().update())
let mut index = index.lock().unwrap(); .await
.expect("blocking index update task should never panic")?;
index.update()
})
.await??;
Ok(()) Ok(())
} }
} }