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

View file

@ -181,7 +181,7 @@ impl Manager {
let worker_config = worker_config.clone();
manager_arbiter.spawn(async move {
let mut worker_arbiter = Arbiter::new();
let mut worker_arbiter = ArbiterDropper::new();
loop {
let notifier = DropNotifier::default();
@ -200,10 +200,9 @@ impl Manager {
metrics::counter!("background-jobs.worker-arbiter.restart", 1, "number" => i.to_string());
tracing::warn!("Recovering from dead worker arbiter");
worker_arbiter.stop();
let _ = worker_arbiter.join();
drop(worker_arbiter);
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
///
/// In previous versions of this library, the server itself was run on it's own dedicated threads