mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-24 11:36:31 +00:00
Refactor block resync loop; make workers infaillible
This commit is contained in:
@@ -76,16 +76,13 @@ impl BackgroundRunner {
|
||||
pub 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,
|
||||
T: Future<Output = ()> + Send + 'static,
|
||||
{
|
||||
let mut workers = self.workers.lock().unwrap();
|
||||
let stop_signal = self.stop_signal.clone();
|
||||
workers.push(tokio::spawn(async move {
|
||||
if let Err(e) = worker(stop_signal).await {
|
||||
error!("Worker stopped with error: {}, error: {}", name, e);
|
||||
} else {
|
||||
info!("Worker exited successfully: {}", name);
|
||||
}
|
||||
worker(stop_signal).await;
|
||||
info!("Worker exited: {}", name);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user