From 23e12a84e3a79aa10af4610a1a8f64e7aa010fce Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Sun, 23 Nov 2025 17:10:00 +0100 Subject: [PATCH] reopen crates-index every time we check --- src/bin/cratesfyi.rs | 9 ++++----- src/utils/daemon.rs | 20 ++++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index f5bdd5a2e..5832eec8d 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -206,11 +206,10 @@ impl CommandLine { start_background_metrics_webserver(Some(metric_server_socket_addr), &ctx)?; - ctx.runtime.block_on(async move { - let index = Index::from_config(&ctx.config).await?; - docs_rs::utils::watch_registry(&ctx.async_build_queue, &ctx.config, &index) - .await - })?; + ctx.runtime.block_on(docs_rs::utils::watch_registry( + &ctx.async_build_queue, + &ctx.config, + ))?; } Self::StartBuildServer { metric_server_socket_addr, diff --git a/src/utils/daemon.rs b/src/utils/daemon.rs index ce0da0a93..29973b06b 100644 --- a/src/utils/daemon.rs +++ b/src/utils/daemon.rs @@ -20,11 +20,7 @@ use tracing::{debug, info, trace}; /// Run the registry watcher /// NOTE: this should only be run once, otherwise crates would be added /// to the queue multiple times. -pub async fn watch_registry( - build_queue: &AsyncBuildQueue, - config: &Config, - index: &Index, -) -> Result<(), Error> { +pub async fn watch_registry(build_queue: &AsyncBuildQueue, config: &Config) -> Result<(), Error> { let mut last_gc = Instant::now(); loop { @@ -32,19 +28,20 @@ pub async fn watch_registry( debug!("Queue is locked, skipping checking new crates"); } else { debug!("Checking new crates"); + let index = Index::from_config(config).await?; match build_queue - .get_new_crates(index) + .get_new_crates(&index) .await .context("Failed to get new crates") { Ok(n) => debug!("{} crates added to queue", n), Err(e) => report_error(&e), } - } - if last_gc.elapsed().as_secs() >= config.registry_gc_interval { - index.run_git_gc().await; - last_gc = Instant::now(); + if last_gc.elapsed().as_secs() >= config.registry_gc_interval { + index.run_git_gc().await; + last_gc = Instant::now(); + } } tokio::time::sleep(config.delay_between_registry_fetches).await; } @@ -58,8 +55,7 @@ fn start_registry_watcher(context: &Context) -> Result<(), Error> { // space this out to prevent it from clashing against the queue-builder thread on launch tokio::time::sleep(Duration::from_secs(30)).await; - let index = Index::from_config(&config).await?; - watch_registry(&build_queue, &config, &index).await + watch_registry(&build_queue, &config).await }); Ok(())