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>

source

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.

source

pub fn wid(&mut self, wid: String) -> &mut Self

Set a unique identifier for this worker.

Defaults to a randomly generated ASCII string.

source

pub fn labels(&mut self, labels: Vec<String>) -> &mut Self

Set the labels to use for this worker.

Defaults to ["rust"].

source

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.

source

pub fn register<K, H>(&mut self, kind: K, handler: H) -> &mut Self
where 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.

source

pub fn register_runner<K, H>(&mut self, kind: K, runner: H) -> &mut Self
where K: Into<String>, H: JobRunner<Error = E> + 'static,

Register a handler for the given job type (kind).

Whenever a job whose type matches kind is fetched from the Faktory, the given handler object is called with that job as its argument.

source

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.

source

pub fn connect_with<S: Read + Write>( self, stream: S, pwd: Option<String> ) -> Result<Consumer<S, E>, Error>

Connect to a Faktory server with a non-standard stream.

Trait Implementations§

source§

impl<E> Default for ConsumerBuilder<E>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<E> !RefUnwindSafe for ConsumerBuilder<E>

§

impl<E> Send for ConsumerBuilder<E>

§

impl<E> Sync for ConsumerBuilder<E>

§

impl<E> Unpin for ConsumerBuilder<E>

§

impl<E> !UnwindSafe for ConsumerBuilder<E>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V