Struct background_jobs::SpawnerConfig
source · pub struct SpawnerConfig { /* private fields */ }
Expand description
SpawnerConfig is the only part of this library required to actually exist in your application.
This type is used to queue new jobs into the background-jobs
server.
ⓘ
let spawner = SpawnerConfig::new("localhost", 5555);
tokio::spawn(
spawner
.queue::<MyProcessor, _>(job)
.map_err(|_| ()),
);
Implementations
sourceimpl SpawnerConfig
impl SpawnerConfig
sourcepub fn new(server_host: &str, base_port: usize) -> SpawnerConfig
pub fn new(server_host: &str, base_port: usize) -> SpawnerConfig
Create a SpawnerConfig
server_host
is the hostname or IP address of the host that the server is running onbase_port
is the samebase_port
from the server config. The spawner will only ever need to communicate overbase_port
sourcepub fn new_with_context(
server_host: &str,
base_port: usize,
ctx: Arc<Context>
) -> SpawnerConfig
pub fn new_with_context(
server_host: &str,
base_port: usize,
ctx: Arc<Context>
) -> SpawnerConfig
The same as SpawnerConfig::new()
, but with a provided ZeroMQ Context.
This can be useful if you have other uses of ZeroMQ in your application, and want to share a context with your dependencies.
If you’re running the Server, Worker, and Spawner in the same application, you should share a ZeroMQ context between them.
sourcepub fn queue<P, S>(
&self,
job: <P as Processor<S>>::Job
) -> impl Future<Item = (), Error = Error>where
P: Processor<S>,
S: 'static + Clone + Send + Sync,
pub fn queue<P, S>(
&self,
job: <P as Processor<S>>::Job
) -> impl Future<Item = (), Error = Error>where
P: Processor<S>,
S: 'static + Clone + Send + Sync,
Queue a job to be executed in the background
sourcepub fn queue_sync<P, S>(
&self,
job: <P as Processor<S>>::Job
) -> Result<(), Error>where
P: Processor<S>,
S: 'static + Clone + Send + Sync,
pub fn queue_sync<P, S>(
&self,
job: <P as Processor<S>>::Job
) -> Result<(), Error>where
P: Processor<S>,
S: 'static + Clone + Send + Sync,
queue_sync
is the same as Queue, except that it blocks the current thread while it is
sending the message to the jobs server.
If you have a tokio-based application, you should use queue
instead.
Auto Trait Implementations
impl RefUnwindSafe for SpawnerConfig
impl Send for SpawnerConfig
impl Sync for SpawnerConfig
impl Unpin for SpawnerConfig
impl UnwindSafe for SpawnerConfig
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more