Struct faktory::ConsumerBuilder
source · pub struct ConsumerBuilder<E> { /* private fields */ }
Expand description
Convenience wrapper for building a Faktory worker.
See the Consumer
documentation for details.
Implementations§
source§impl<E> ConsumerBuilder<E>
impl<E> ConsumerBuilder<E>
sourcepub fn hostname(&mut self, hn: String) -> &mut Self
pub fn hostname(&mut self, hn: String) -> &mut Self
Set the hostname to use for this worker.
Defaults to the machine’s hostname as reported by the operating system.
sourcepub fn wid(&mut self, wid: String) -> &mut Self
pub fn wid(&mut self, wid: String) -> &mut Self
Set a unique identifier for this worker.
Defaults to a randomly generated ASCII string.
sourcepub fn labels(&mut self, labels: Vec<String>) -> &mut Self
pub fn labels(&mut self, labels: Vec<String>) -> &mut Self
Set the labels to use for this worker.
Defaults to ["rust"]
.
sourcepub fn workers(&mut self, w: usize) -> &mut Self
pub fn workers(&mut self, w: usize) -> &mut Self
Set the number of workers to use for run
and run_to_completion_*
.
Defaults to 1.
sourcepub fn register<K, H>(&mut self, kind: K, handler: H) -> &mut Selfwhere
K: Into<String>,
H: Fn(Job) -> Result<(), E> + Send + Sync + 'static,
pub fn register<K, H>(&mut self, kind: K, handler: H) -> &mut Selfwhere
K: Into<String>,
H: Fn(Job) -> Result<(), E> + Send + Sync + 'static,
Register a handler function for the given job type (kind
).
Whenever a job whose type matches kind
is fetched from the Faktory, the given handler
function is called with that job as its argument.
sourcepub fn connect(self, url: Option<&str>) -> Result<Consumer<TcpStream, E>, Error>
pub fn connect(self, url: Option<&str>) -> Result<Consumer<TcpStream, E>, Error>
Connect to a Faktory server.
If url
is not given, will use the standard Faktory environment variables. Specifically,
FAKTORY_PROVIDER
is read to get the name of the environment variable to get the address
from (defaults to FAKTORY_URL
), and then that environment variable is read to get the
server address. If the latter environment variable is not defined, the connection will be
made to
tcp://localhost:7419
If url
is given, but does not specify a port, it defaults to 7419.