pub struct Worker { /* private fields */ }Expand description
Distributed task worker
Implementations§
Source§impl Worker
impl Worker
Sourcepub fn new(config: Config) -> Self
pub fn new(config: Config) -> Self
Creates a new worker with the given configuration
§Arguments
config- Worker configuration
§Example
use go_server_rust_sdk::worker::{Worker, Config};
let config = Config {
scheduler_url: "ws://localhost:8080/api/worker/connect/123456".to_string(),
worker_group: "math".to_string(),
max_retry: 5,
ping_interval: 5,
};
let worker = Worker::new(config);Sourcepub fn register_method<F>(
&mut self,
name: impl Into<String>,
handler: F,
docs: Vec<String>,
)
pub fn register_method<F>( &mut self, name: impl Into<String>, handler: F, docs: Vec<String>, )
Registers a method handler with the worker
§Arguments
name- Method namehandler- Function that handles the method calldocs- Documentation strings for the method
§Example
use go_server_rust_sdk::worker::{Worker, Config};
use serde_json::{json, Value};
let mut worker = Worker::new(config);
worker.register_method("add", |params: Value| {
let a = params["a"].as_f64().unwrap_or(0.0);
let b = params["b"].as_f64().unwrap_or(0.0);
Ok(json!(a + b))
}, vec!["Add two numbers".to_string()]);Auto Trait Implementations§
impl Freeze for Worker
impl !RefUnwindSafe for Worker
impl Send for Worker
impl Sync for Worker
impl Unpin for Worker
impl !UnwindSafe for Worker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more