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]

[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"].

[src]

Re-establish this worker's connection to the Faktory server using default environment variables.

[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]

[src]

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.

[src]

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.

Trait Implementations

impl<F, S: Read + Write> From<Client<S>> for Consumer<S, F>
[src]

[src]

Performs the conversion.