Support suspending background thread

Useful for locally testing query timings with sqlx debug logging.
This commit is contained in:
nora 2025-07-04 23:09:52 +02:00
parent 6df7155a50
commit 5fb3ca86b2

View file

@ -52,6 +52,13 @@ impl Display for Toolchain {
}
pub async fn background_builder(db: Db) -> Result<()> {
if concurrent_jobs() == 0 {
info!("Suspending background thread since DOES_IT_BUILD_PARALLEL_JOBS=0");
loop {
tokio::time::sleep(Duration::from_secs(3600)).await;
}
}
loop {
if let Err(err) = background_builder_inner(&db).await {
error!("error in background builder: {err}");
@ -192,21 +199,12 @@ pub async fn build_every_target_for_toolchain(
.await
.wrap_err("failed to get targets")?;
let concurrent = std::env::var("DOES_IT_BUILD_PARALLEL_JOBS")
.map(|jobs| jobs.parse().unwrap())
.unwrap_or_else(|_| {
std::thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(2).unwrap())
.get()
/ 2
});
let results = futures::stream::iter(
targets
.iter()
.map(|target| build_single_target(db, nightly, target, mode)),
)
.buffer_unordered(concurrent)
.buffer_unordered(concurrent_jobs())
.collect::<Vec<Result<()>>>()
.await;
for result in results {
@ -354,3 +352,14 @@ async fn build_target(
rustflags,
})
}
fn concurrent_jobs() -> usize {
std::env::var("DOES_IT_BUILD_PARALLEL_JOBS")
.map(|jobs| jobs.parse().unwrap())
.unwrap_or_else(|_| {
std::thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(2).unwrap())
.get()
/ 2
})
}