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

View file

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

View file

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

View file

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