Struct background_jobs_server::WorkerConfig
source · pub struct WorkerConfig { /* 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 WorkerConfig
impl WorkerConfig
sourcepub fn new(
server_host: String,
base_port: usize,
queues: BTreeMap<String, usize>
) -> Self
pub fn new(
server_host: String,
base_port: usize,
queues: BTreeMap<String, usize>
) -> Self
Create a new worker
This method takes three arguments
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(
server_host: String,
base_port: usize,
queues: BTreeMap<String, usize>,
context: Arc<Context>
) -> Self
pub fn new_with_context(
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 !RefUnwindSafe for WorkerConfig
impl Send for WorkerConfig
impl Sync for WorkerConfig
impl Unpin for WorkerConfig
impl !UnwindSafe for WorkerConfig
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