actix: Add start_in_arbiter_handle

This commit is contained in:
Aode (Lion) 2021-10-06 21:09:07 -05:00
parent 5828b3d68a
commit 1ce008e8c4
2 changed files with 19 additions and 10 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "background-jobs-actix"
description = "in-process jobs processor based on Actix"
version = "0.9.1"
version = "0.9.2"
license-file = "../LICENSE"
authors = ["asonix <asonix@asonix.dog>"]
repository = "https://git.asonix.dog/Aardwolf/background-jobs"

View file

@ -209,15 +209,9 @@ where
///
/// This method will panic if not called from an actix runtime
pub fn start(self, queue_handle: QueueHandle) {
for (key, count) in self.queues.into_iter() {
for _ in 0..count {
local_worker(
key.clone(),
self.processors.cached(),
queue_handle.inner.clone(),
);
}
}
let handle = Arbiter::current();
self.start_in_arbiter_handle(&handle, queue_handle);
}
/// Start the workers in the provided arbiter
@ -234,6 +228,21 @@ where
}
}
}
/// Start the workers in the provided arbiter via it's handle
pub fn start_in_arbiter_handle(self, arbiter: &ArbiterHandle, queue_handle: QueueHandle) {
for (key, count) in self.queues.into_iter() {
for _ in 0..count {
let key = key.clone();
let processors = self.processors.clone();
let server = queue_handle.inner.clone();
arbiter.spawn_fn(move || {
local_worker(key, processors.cached(), server);
});
}
}
}
}
/// A handle to the job server, used for queuing new jobs