Skip to content

Commit ef9f424

Browse files
committed
reopen crates-index every time we check
1 parent c1de1ad commit ef9f424

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

src/bin/cratesfyi.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,10 @@ impl CommandLine {
206206

207207
start_background_metrics_webserver(Some(metric_server_socket_addr), &ctx)?;
208208

209-
ctx.runtime.block_on(async move {
210-
let index = Index::from_config(&ctx.config).await?;
211-
docs_rs::utils::watch_registry(&ctx.async_build_queue, &ctx.config, &index)
212-
.await
213-
})?;
209+
ctx.runtime.block_on(docs_rs::utils::watch_registry(
210+
&ctx.async_build_queue,
211+
&ctx.config,
212+
))?;
214213
}
215214
Self::StartBuildServer {
216215
metric_server_socket_addr,

src/utils/daemon.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,28 @@ use tracing::{debug, info, trace};
2020
/// Run the registry watcher
2121
/// NOTE: this should only be run once, otherwise crates would be added
2222
/// to the queue multiple times.
23-
pub async fn watch_registry(
24-
build_queue: &AsyncBuildQueue,
25-
config: &Config,
26-
index: &Index,
27-
) -> Result<(), Error> {
23+
pub async fn watch_registry(build_queue: &AsyncBuildQueue, config: &Config) -> Result<(), Error> {
2824
let mut last_gc = Instant::now();
2925

3026
loop {
3127
if build_queue.is_locked().await? {
3228
debug!("Queue is locked, skipping checking new crates");
3329
} else {
3430
debug!("Checking new crates");
31+
let index = Index::from_config(config).await?;
3532
match build_queue
36-
.get_new_crates(index)
33+
.get_new_crates(&index)
3734
.await
3835
.context("Failed to get new crates")
3936
{
4037
Ok(n) => debug!("{} crates added to queue", n),
4138
Err(e) => report_error(&e),
4239
}
43-
}
4440

45-
if last_gc.elapsed().as_secs() >= config.registry_gc_interval {
46-
index.run_git_gc().await;
47-
last_gc = Instant::now();
41+
if last_gc.elapsed().as_secs() >= config.registry_gc_interval {
42+
index.run_git_gc().await;
43+
last_gc = Instant::now();
44+
}
4845
}
4946
tokio::time::sleep(config.delay_between_registry_fetches).await;
5047
}
@@ -58,8 +55,7 @@ fn start_registry_watcher(context: &Context) -> Result<(), Error> {
5855
// space this out to prevent it from clashing against the queue-builder thread on launch
5956
tokio::time::sleep(Duration::from_secs(30)).await;
6057

61-
let index = Index::from_config(&config).await?;
62-
watch_registry(&build_queue, &config, &index).await
58+
watch_registry(&build_queue, &config).await
6359
});
6460

6561
Ok(())

0 commit comments

Comments
 (0)