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

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 the ServerConfig 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, and base_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.

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.

Register a processor with this worker

For more information, see Processor.

Start the workers

This method returns a future that, when run, spawns all of the worker’s required futures onto tokio. Therefore, this can only be used from tokio.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.