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",
]
[[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"
@ -2697,6 +2703,7 @@ dependencies = [
"crates-index",
"derive_more",
"dotenvy",
"error_reporter",
"font-awesome-as-a-crate",
"futures-util",
"gix",
@ -2705,6 +2712,7 @@ dependencies = [
"lru_time_cache",
"maud",
"once_cell",
"parking_lot",
"pulldown-cmark",
"relative-path",
"reqwest",

View file

@ -24,10 +24,12 @@ 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]
#[tokio::main(flavor = "current_thread")]
async fn main() {
dotenvy::dotenv().ok();
init_tracing_subscriber();
@ -98,10 +98,9 @@ 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,9 +26,7 @@ impl ManagedIndex {
}
pub fn crate_(&self, crate_name: CrateName) -> Option<Crate> {
let index = self.index.lock().unwrap();
index.crate_(crate_name.as_ref())
self.index.lock().unwrap().crate_(crate_name.as_ref())
}
pub async fn refresh_at_interval(&self, update_interval: Duration) {
@ -38,22 +36,21 @@ impl ManagedIndex {
loop {
if let Err(err) = self.refresh().await {
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;
}
}
async fn refresh(&self) -> Result<()> {
async fn refresh(&self) -> Result<(), crates_index::Error> {
let index = Arc::clone(&self.index);
spawn_blocking(move || {
let mut index = index.lock().unwrap();
spawn_blocking(move || index.lock().unwrap().update())
.await
.expect("blocking index update task should never panic")?;
index.update()
})
.await??;
Ok(())
}
}