aboutsummaryrefslogtreecommitdiff
path: root/src/background.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-19 21:33:38 +0000
committerAlex Auvolat <alex@adnab.me>2020-04-19 21:33:38 +0000
commit53cf4d1baaa994544c02ec12f4bea28598720aa8 (patch)
treefef3fc9538e28682b1f91a65f818b7095ef27a16 /src/background.rs
parentec7f9f07e21ca2771d348b84c6cb14eda64e501c (diff)
downloadgarage-53cf4d1baaa994544c02ec12f4bea28598720aa8.tar.gz
garage-53cf4d1baaa994544c02ec12f4bea28598720aa8.zip
Log which workers are doing what
Diffstat (limited to 'src/background.rs')
-rw-r--r--src/background.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/background.rs b/src/background.rs
index 34e96ff7..b9a4684a 100644
--- a/src/background.rs
+++ b/src/background.rs
@@ -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;