mirror of
https://git.deuxfleurs.fr/Deuxfleurs/garage.git
synced 2024-11-21 15:41:02 +00:00
Log which workers are doing what
This commit is contained in:
parent
ec7f9f07e2
commit
53cf4d1baa
5 changed files with 25 additions and 16 deletions
|
@ -182,7 +182,9 @@ impl AdminRpcHandler {
|
|||
self.garage
|
||||
.system
|
||||
.background
|
||||
.spawn_worker(move |must_exit| async move { self2.repair_worker(must_exit).await })
|
||||
.spawn_worker("Repair worker".into(), move |must_exit| async move {
|
||||
self2.repair_worker(must_exit).await
|
||||
})
|
||||
.await;
|
||||
Ok(AdminRPC::Ok(format!(
|
||||
"Repair launched on {:?}",
|
||||
|
|
|
@ -36,8 +36,8 @@ impl BackgroundRunner {
|
|||
|
||||
pub async fn run(self: Arc<Self>) {
|
||||
let mut workers = self.workers.lock().await;
|
||||
for _i in 0..self.n_runners {
|
||||
workers.push(tokio::spawn(self.clone().runner()));
|
||||
for i in 0..self.n_runners {
|
||||
workers.push(tokio::spawn(self.clone().runner(i)));
|
||||
}
|
||||
drop(workers);
|
||||
|
||||
|
@ -68,7 +68,7 @@ impl BackgroundRunner {
|
|||
let _: Result<_, _> = self.queue_in.clone().send((boxed, true));
|
||||
}
|
||||
|
||||
pub async fn spawn_worker<F, T>(&self, worker: F)
|
||||
pub async fn spawn_worker<F, T>(&self, name: String, worker: F)
|
||||
where
|
||||
F: FnOnce(watch::Receiver<bool>) -> T + Send + 'static,
|
||||
T: Future<Output = JobOutput> + Send + 'static,
|
||||
|
@ -77,14 +77,14 @@ impl BackgroundRunner {
|
|||
let stop_signal = self.stop_signal.clone();
|
||||
workers.push(tokio::spawn(async move {
|
||||
if let Err(e) = worker(stop_signal).await {
|
||||
eprintln!("Worker stopped with error: {}", e);
|
||||
eprintln!("Worker stopped with error: {}, error: {}", name, e);
|
||||
} else {
|
||||
println!("A worker exited successfully (which one?)");
|
||||
println!("Worker exited successfully: {}", name);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
async fn runner(self: Arc<Self>) {
|
||||
async fn runner(self: Arc<Self>, i: usize) {
|
||||
let stop_signal = self.stop_signal.clone();
|
||||
loop {
|
||||
let must_exit: bool = *stop_signal.borrow();
|
||||
|
@ -94,6 +94,7 @@ impl BackgroundRunner {
|
|||
}
|
||||
} else {
|
||||
if must_exit {
|
||||
eprintln!("Background runner {} exiting", i);
|
||||
return;
|
||||
}
|
||||
tokio::time::delay_for(Duration::from_secs(1)).await;
|
||||
|
|
|
@ -107,11 +107,13 @@ impl BlockManager {
|
|||
|
||||
pub async fn spawn_background_worker(self: Arc<Self>) {
|
||||
// Launch 2 simultaneous workers for background resync loop preprocessing
|
||||
for _i in 0..2usize {
|
||||
for i in 0..2usize {
|
||||
let bm2 = self.clone();
|
||||
self.system
|
||||
.background
|
||||
.spawn_worker(move |must_exit| bm2.resync_loop(must_exit))
|
||||
.spawn_worker(format!("block resync worker {}", i), move |must_exit| {
|
||||
bm2.resync_loop(must_exit)
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -391,7 +391,9 @@ impl System {
|
|||
|
||||
self.clone()
|
||||
.background
|
||||
.spawn_worker(|stop_signal| self.ping_loop(stop_signal).map(Ok))
|
||||
.spawn_worker(format!("ping loop"), |stop_signal| {
|
||||
self.ping_loop(stop_signal).map(Ok)
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
|
|
|
@ -96,18 +96,20 @@ where
|
|||
table
|
||||
.system
|
||||
.background
|
||||
.spawn_worker(move |must_exit: watch::Receiver<bool>| {
|
||||
s1.watcher_task(must_exit, busy_rx)
|
||||
})
|
||||
.spawn_worker(
|
||||
format!("table sync watcher for {}", table.name),
|
||||
move |must_exit: watch::Receiver<bool>| s1.watcher_task(must_exit, busy_rx),
|
||||
)
|
||||
.await;
|
||||
|
||||
let s2 = syncer.clone();
|
||||
table
|
||||
.system
|
||||
.background
|
||||
.spawn_worker(move |must_exit: watch::Receiver<bool>| {
|
||||
s2.syncer_task(must_exit, busy_tx)
|
||||
})
|
||||
.spawn_worker(
|
||||
format!("table syncer for {}", table.name),
|
||||
move |must_exit: watch::Receiver<bool>| s2.syncer_task(must_exit, busy_tx),
|
||||
)
|
||||
.await;
|
||||
|
||||
syncer
|
||||
|
|
Loading…
Reference in a new issue