Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 8 additions & 12 deletions src/utils/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,28 @@ 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 {
if build_queue.is_locked().await? {
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;
}
Expand All @@ -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(())
Expand Down
Loading