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.
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();
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.
Unregisters a previously registered function, notifying the server that
this worker is not available anymore to process jobs with the specified name
.
Notify the gearman queue server that we are available/unavailable to process
jobs with the specified name
.
Let the server know that the worker identifies itself with the associated id
.
Ask the server to do some work. This will process one job that will be provided by
the gearman queue server when available.
Process any available job as soon as the gearman queue server provides us with one
in a loop.
Estabilish a connection with the queue server and send it the ID of this worker.
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static