[][src]Struct gearman_worker::Worker

pub struct Worker { /* fields omitted */ }

The Worker processes jobs provided by the gearman queue server.

Building a worker requires a SocketAddr to connect to the gearman server (typically some ip address on port 4730).

The worker also needs a unique id to identify itself to the server. This can be omitted letting the WorkerBuilder generate one composed by the process id and a random uuid v4.

Examples

Create a worker with all default options.

use gearman_worker::WorkerBuilder;
let mut worker = WorkerBuilder::default().build();

Create a worker with all explicit options.

use gearman_worker::WorkerBuilder;
let mut worker = WorkerBuilder::new("my-worker-1", "127.0.0.1:4730".parse().unwrap()).build();

Methods

impl Worker
[src]

pub fn register_function<S, F>(&mut self, name: S, callback: F) -> Result<()> where
    S: AsRef<str>,
    F: Fn(&[u8]) -> Result<Vec<u8>, Option<Vec<u8>>> + 'static, 
[src]

Registers a callback function that can handle jobs with the specified name provided by the gearman queue server.

The callback has the signature Fn(&[u8]) -> WorkResult + 'static receiving a slice of bytes in input, which is the workload received from the gearmand server.

It can return Ok(Vec<u8>) (WORK_COMPLETE) where the vector of bytes is the result of the job that will be transmitted back to the server, Err(None) (WORK_EXCEPTION) which will tell the server that the job failed with an unspecified error or Err(Some(Vec<u8>)) (WORK_FAIL) which will also represent a job failure but will include a payload of the error to the gearmand server.

pub fn unregister_function<S>(&mut self, name: S) -> Result<()> where
    S: AsRef<str>, 
[src]

Unregisters a previously registered function, notifying the server that this worker is not available anymore to process jobs with the specified name.

pub fn set_function_enabled<S>(&mut self, name: S, enabled: bool) -> Result<()> where
    S: AsRef<str>, 
[src]

Notify the gearman queue server that we are available/unavailable to process jobs with the specified name.

pub fn set_client_id(&mut self) -> Result<()>
[src]

Let the server know that the worker identifies itself with the associated id.

pub fn do_work(&mut self) -> Result<u32>
[src]

Ask the server to do some work. This will process one job that will be provided by the gearman queue server when available.

pub fn run(&mut self) -> Result<()>
[src]

Process any available job as soon as the gearman queue server provides us with one in a loop.

pub fn connect(&mut self) -> Result<&mut Self>
[src]

Estabilish a connection with the queue server and send it the ID of this worker.

Auto Trait Implementations

impl !Send for Worker

impl !Sync for Worker

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]