Struct faktory::Consumer
[−]
[src]
pub struct Consumer<S, F> where
S: Read + Write, { /* fields omitted */ }
This struct represents a single Faktory worker.
The worker consumes jobs fetched from the Faktory server, processes them, and reports the results back to the Faktory server upon completion.
A worker should be constructed using a ConsumerBuilder
, so
that any non-default worker parameters can be set.
use std::io; use std::net::TcpStream; let mut c = ConsumerBuilder::default().connect_env::<TcpStream, _>().unwrap(); c.register("foobar", |job| -> io::Result<()> { println!("{:?}", job); Ok(()) }); if let Err(e) = c.run(&["default"]) { println!("worker failed: {}", e); }
Methods
impl<F, S: StreamConnector> Consumer<S, F>
[src]
fn default() -> Result<Self>
[src]
Construct a new worker with default worker options and the url fetched from environment variables.
This will construct a worker where:
hostname
is this machine's hostname.wid
is a randomly generated string.pid
is the OS PID of this process.labels
is["rust"]
.
fn reconnect_env(&mut self) -> Result<()>
[src]
Re-establish this worker's connection to the Faktory server using default environment variables.
fn reconnect<U: AsRef<str>>(&mut self, url: U) -> Result<()>
[src]
Re-establish this worker's connection to the Faktory server using the given url
.
impl<S, E, F> Consumer<S, F> where
S: Read + Write + Send + 'static,
E: Error,
F: FnMut(Job) -> Result<(), E>,
[src]
S: Read + Write + Send + 'static,
E: Error,
F: FnMut(Job) -> Result<(), E>,
fn register<K>(&mut self, kind: K, handler: F) where
K: ToString,
[src]
K: ToString,
Register a handler function for the given kind
of job.
Whenever a job whose type matches kind
is fetched from the Faktory, the given handler
function is called with that job.
fn run<Q>(self, queues: &[Q]) -> Result<()> where
Q: AsRef<str>,
[src]
Q: AsRef<str>,
Run this worker on the given queues
until an I/O error occurs, or until the server tells
the worker to disengage.
Note that if the worker fails, reconnect()
should likely be called before calling run()
again. If an error occurred while reporting a job success or failure, the result will be
re-reported to the server without re-executing the job.