Crates.io | gearman-worker |
lib.rs | gearman-worker |
version | 0.3.0 |
source | src |
created_at | 2018-07-12 15:06:57.768328 |
updated_at | 2019-01-27 22:39:45.061248 |
description | High level library to implement Gearman workers |
homepage | https://github.com/mtorromeo/gearman-worker-rs |
repository | https://github.com/mtorromeo/gearman-worker-rs.git |
max_upload_size | |
id | 73934 |
size | 25,882 |
High level library to implement Gearman workers.
Add this dependency to your Cargo.toml
gearman-worker = "*"
extern crate gearman_worker;
use gearman_worker::Worker;
fn main() {
let server_addr = "127.0.0.1:4730".parse().unwrap();
let mut worker = WorkerBuilder::new("my-worker-rs-1", server_addr).build();
worker.connect().unwrap();
worker.register_function("greet", |input| {
let hello = String::from_utf8_lossy(input);
let response = format!("{} world!", hello);
Ok(response.into_bytes())
}).unwrap();
worker.run().unwrap();
}
where the worker functions have the following signature:
Fn(&[u8]) -> Result<Vec<u8>, Option<Vec<u8>>>;
This has not been tested yet with a real workload and the public interface will probably change in the future.
The worker runs in a single thread using blocking tcp connections. This is fine if you don't expect high concurrency and you can always spawn multiple separate processes to handle the workload but I plan on implementing multi-threading and non-blocking io (probably with tokio).
The following gearman operations are not currently supported but the typical use-case is implemented:
WORK_STATUS
CAN_DO_TIMEOUT
WORK_DATA
WORK_WARNING
GRAB_JOB_UNIQ
GRAB_JOB_ALL
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email massimiliano.torromeo@gmail.com instead of using the issue tracker.
This software is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.