Add back ArbiterDropper

This commit is contained in:
asonix 2022-11-19 21:44:17 -06:00
parent 1a9efc8a49
commit 9869fe7cb3
2 changed files with 32 additions and 5 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "background-jobs-actix" name = "background-jobs-actix"
description = "in-process jobs processor based on Actix" description = "in-process jobs processor based on Actix"
version = "0.14.1" version = "0.14.2"
license = "AGPL-3.0" license = "AGPL-3.0"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/asonix/background-jobs" repository = "https://git.asonix.dog/asonix/background-jobs"

View file

@ -181,7 +181,7 @@ impl Manager {
let worker_config = worker_config.clone(); let worker_config = worker_config.clone();
manager_arbiter.spawn(async move { manager_arbiter.spawn(async move {
let mut worker_arbiter = Arbiter::new(); let mut worker_arbiter = ArbiterDropper::new();
loop { loop {
let notifier = DropNotifier::default(); let notifier = DropNotifier::default();
@ -200,10 +200,9 @@ impl Manager {
metrics::counter!("background-jobs.worker-arbiter.restart", 1, "number" => i.to_string()); metrics::counter!("background-jobs.worker-arbiter.restart", 1, "number" => i.to_string());
tracing::warn!("Recovering from dead worker arbiter"); tracing::warn!("Recovering from dead worker arbiter");
worker_arbiter.stop(); drop(worker_arbiter);
let _ = worker_arbiter.join();
worker_arbiter = Arbiter::new(); worker_arbiter = ArbiterDropper::new();
} }
}); });
} }
@ -249,6 +248,34 @@ impl Drop for DropNotifier {
} }
} }
struct ArbiterDropper {
arbiter: Option<Arbiter>,
}
impl ArbiterDropper {
fn new() -> Self {
Self {
arbiter: Some(Arbiter::new()),
}
}
}
impl Deref for ArbiterDropper {
type Target = Arbiter;
fn deref(&self) -> &Self::Target {
self.arbiter.as_ref().unwrap()
}
}
impl Drop for ArbiterDropper {
fn drop(&mut self) {
let arbiter = self.arbiter.take().unwrap();
arbiter.stop();
let _ = arbiter.join();
}
}
/// Create a new managed Server /// Create a new managed Server
/// ///
/// In previous versions of this library, the server itself was run on it's own dedicated threads /// In previous versions of this library, the server itself was run on it's own dedicated threads