Struct background_jobs_server::WorkerConfig
source · pub struct WorkerConfig<S>where
S: Clone,{ /* private fields */ }
Expand description
The entry point for creating a background-jobs worker.
A worker handles the processing of jobs, but not the queueing or storing of jobs. It connects
to a server (crated with
ServerConfig
)
and receives work from there.
use std::collections::BTreeMap;
use background_jobs_server::WorkerConfig;
use failure::Error;
fn main() -> Result<(), Error> {
let mut queue_map = BTreeMap::new();
queue_map.insert("default".to_owned(), 10);
let mut worker = WorkerConfig::new((), "localhost".to_owned(), 5555, queue_map);
// Register a processor
// worker.register_processor(MyProcessor);
// Run the workers
// tokio::run(worker.run());
Ok(())
}
Implementations
sourceimpl<S> WorkerConfig<S>where
S: Clone + Send + Sync + 'static,
impl<S> WorkerConfig<S>where
S: Clone + Send + Sync + 'static,
sourcepub fn new(
state: S,
server_host: String,
base_port: usize,
queues: BTreeMap<String, usize>
) -> Self
pub fn new(
state: S,
server_host: String,
base_port: usize,
queues: BTreeMap<String, usize>
) -> Self
Create a new worker
This method takes four arguments
- The state passed into this method will be passed to all jobs executed on this Worker. The state argument could be useful for containing a hook into something like r2d2, or the address of an actor in an actix-based system.
server_host
is the hostname, or IP address, of the background-jobs server.base_port
is the same value from theServerConfig
initialization. It dictates the port the worker uses to return jobs to the server. The worker is guaranteed to connect to at least 2 other ports on the server when functioning properly,base_port
+ 1, andbase_port
+ n.- queues is a mapping between the name of a queue, and the number of workers that should be started to process jobs in that queue.
sourcepub fn new_with_context(
state: S,
server_host: String,
base_port: usize,
queues: BTreeMap<String, usize>,
context: Arc<Context>
) -> Self
pub fn new_with_context(
state: S,
server_host: String,
base_port: usize,
queues: BTreeMap<String, usize>,
context: Arc<Context>
) -> Self
The same as WorkerConfig::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.
Auto Trait Implementations
impl<S> !RefUnwindSafe for WorkerConfig<S>
impl<S> Send for WorkerConfig<S>where
S: Send,
impl<S> Sync for WorkerConfig<S>where
S: Sync,
impl<S> Unpin for WorkerConfig<S>where
S: Unpin,
impl<S> !UnwindSafe for WorkerConfig<S>
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