pub struct Client { /* private fields */ }Expand description
Scheduler client for executing tasks
Implementations§
Source§impl Client
impl Client
Sourcepub async fn execute(
&self,
method: impl Into<String>,
params: Value,
) -> Result<ResultResponse>
pub async fn execute( &self, method: impl Into<String>, params: Value, ) -> Result<ResultResponse>
Executes a task with the given method and parameters
§Arguments
method- The method name to executeparams- The parameters for the method
§Returns
A ResultResponse containing the task ID and initial status
§Example
use go_server_rust_sdk::scheduler::Client;
use serde_json::json;
let client = Client::new("http://localhost:8080");
let params = json!({"a": 10, "b": 20});
let response = client.execute("add", params).await?;
println!("Task ID: {}", response.task_id);Sourcepub async fn execute_encrypted(
&self,
method: impl Into<String>,
key: &str,
salt: i32,
params: Value,
) -> Result<ResultResponse>
pub async fn execute_encrypted( &self, method: impl Into<String>, key: &str, salt: i32, params: Value, ) -> Result<ResultResponse>
Executes an encrypted task with the given method, key, salt and parameters
§Arguments
method- The method name to executekey- The encryption keysalt- The salt value for key encryptionparams- The parameters for the method
§Returns
A ResultResponse containing the task ID and initial status
§Example
use go_server_rust_sdk::scheduler::Client;
use serde_json::json;
let client = Client::new("http://localhost:8080");
let params = json!({"a": 10, "b": 20});
let response = client.execute_encrypted("add", "my-secret-key", 123456, params).await?;
println!("Task ID: {}", response.task_id);Sourcepub async fn get_result(&self, task_id: &str) -> Result<ResultResponse>
pub async fn get_result(&self, task_id: &str) -> Result<ResultResponse>
Retrieves the result of a task by its ID with polling
This method will automatically poll the server until the task is complete or an error occurs.
§Arguments
task_id- The ID of the task to retrieve
§Returns
A ResultResponse containing the final task result
§Example
use go_server_rust_sdk::scheduler::Client;
let client = Client::new("http://localhost:8080");
let result = client.get_result("task-123").await?;
println!("Result: {:?}", result.result);Sourcepub async fn get_result_encrypted(
&self,
task_id: &str,
key: &str,
_salt: i32,
) -> Result<ResultResponse>
pub async fn get_result_encrypted( &self, task_id: &str, key: &str, _salt: i32, ) -> Result<ResultResponse>
Retrieves and decrypts the result of an encrypted task by its ID
This method will automatically poll the server until the task is complete, then decrypt the result using the provided key.
§Arguments
task_id- The ID of the task to retrievekey- The decryption keysalt- The salt value used for encryption
§Returns
A ResultResponse containing the decrypted task result
§Example
use go_server_rust_sdk::scheduler::Client;
let client = Client::new("http://localhost:8080");
let result = client.get_result_encrypted("task-123", "my-secret-key", 123456).await?;
println!("Decrypted result: {:?}", result.result);Sourcepub async fn execute_sync(
&self,
method: impl Into<String>,
params: Value,
timeout_duration: Duration,
) -> Result<ResultResponse>
pub async fn execute_sync( &self, method: impl Into<String>, params: Value, timeout_duration: Duration, ) -> Result<ResultResponse>
Executes a task synchronously with polling and timeout
This is a convenience method that combines execute and get_result
with a timeout.
§Arguments
method- The method name to executeparams- The parameters for the methodtimeout_duration- Maximum time to wait for completion
§Returns
A ResultResponse containing the final task result
§Example
use go_server_rust_sdk::scheduler::Client;
use serde_json::json;
use std::time::Duration;
let client = Client::new("http://localhost:8080");
let params = json!({"a": 10, "b": 20});
let result = client.execute_sync("add", params, Duration::from_secs(30)).await?;
println!("Result: {:?}", result.result);Sourcepub async fn execute_sync_encrypted(
&self,
method: impl Into<String>,
key: &str,
salt: i32,
params: Value,
timeout_duration: Duration,
) -> Result<ResultResponse>
pub async fn execute_sync_encrypted( &self, method: impl Into<String>, key: &str, salt: i32, params: Value, timeout_duration: Duration, ) -> Result<ResultResponse>
Executes an encrypted task synchronously with polling, decryption and timeout
This is a convenience method that combines execute_encrypted and
get_result_encrypted with a timeout.
§Arguments
method- The method name to executekey- The encryption keysalt- The salt value for key encryptionparams- The parameters for the methodtimeout_duration- Maximum time to wait for completion
§Returns
A ResultResponse containing the decrypted task result
§Example
use go_server_rust_sdk::scheduler::Client;
use serde_json::json;
use std::time::Duration;
let client = Client::new("http://localhost:8080");
let params = json!({"a": 10, "b": 20});
let result = client.execute_sync_encrypted(
"add",
"my-secret-key",
123456,
params,
Duration::from_secs(30)
).await?;
println!("Decrypted result: {:?}", result.result);