go_server_rust_sdk/lib.rs
1//! # Go-Server Rust SDK
2//!
3//! This crate provides a Rust SDK for interacting with the go-server distributed task scheduler.
4//! It includes both scheduler client functionality and worker implementation.
5//!
6//! ## Features
7//!
8//! - **Scheduler Client**: Execute tasks on remote workers
9//! - **Worker**: Register and handle distributed tasks
10//! - **Encryption**: Support for encrypted task execution
11//! - **Retry Logic**: Built-in retry mechanisms for reliability
12//!
13//! ## Quick Start
14//!
15//! ### Using the Scheduler Client
16//!
17//! ```rust,no_run
18//! use go_server_rust_sdk::scheduler::Client;
19//! use serde_json::json;
20//!
21//! #[tokio::main]
22//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
23//! let client = Client::new("http://localhost:8080");
24//!
25//! let params = json!({
26//! "a": 10,
27//! "b": 20
28//! });
29//!
30//! let result = client.execute_sync("add", params, std::time::Duration::from_secs(30)).await?;
31//! println!("Result: {:?}", result);
32//!
33//! Ok(())
34//! }
35//! ```
36//!
37//! ### Creating a Worker
38//!
39//! ```rust,no_run
40//! use go_server_rust_sdk::worker::{Worker, Config};
41//! use serde_json::{json, Value};
42//!
43//! #[tokio::main]
44//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
45//! let config = Config {
46//! scheduler_url: "ws://localhost:8080/api/worker/connect/123456".to_string(),
47//! worker_group: "math".to_string(),
48//! max_retry: 5,
49//! ping_interval: 5,
50//! };
51//!
52//! let mut worker = Worker::new(config);
53//!
54//! worker.register_method("add", |params: Value| {
55//! let a = params["a"].as_f64().unwrap_or(0.0);
56//! let b = params["b"].as_f64().unwrap_or(0.0);
57//! Ok(json!(a + b))
58//! }, vec!["Add two numbers".to_string()]);
59//!
60//! worker.start().await?;
61//!
62//! Ok(())
63//! }
64//! ```
65
66pub mod scheduler;
67pub mod worker;
68pub mod crypto;
69pub mod error;
70
71pub use error::{Result, SdkError};
72
73/// Re-export commonly used types
74pub mod prelude {
75 pub use crate::scheduler::{Client, RetryClient, ResultResponse};
76 pub use crate::worker::{Worker, Config as WorkerConfig};
77 pub use crate::error::{Result, SdkError};
78 pub use serde_json::{json, Value};
79}