linting and fmt

This commit is contained in:
timurgordon
2025-06-19 02:32:56 +03:00
parent 4e717bc054
commit 1a3fa6242d
24 changed files with 1024 additions and 620 deletions

View File

@@ -27,7 +27,3 @@ path = "example_string_worker.rs"
[[bin]]
name = "dedicated_reply_queue_demo"
path = "dedicated_reply_queue_demo.rs"
[[bin]]
name = "lua_client_demo"
path = "lua_client_demo.rs"

View File

@@ -1,4 +1,4 @@
use log::{info, error, debug};
use log::{debug, error, info};
use rhai::Engine;
use rhai_client::{RhaiClient, RhaiClientError}; // RhaiTaskDetails is now used for its fields
use rhailib_worker::spawn_rhai_worker;
@@ -55,7 +55,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let task_timeout = Duration::from_secs(10);
let task_id = Uuid::new_v4().to_string(); // Generate a unique task_id
info!("Submitting script to circle '{}' with task_id '{}' and awaiting result...", circle_name, task_id);
info!(
"Submitting script to circle '{}' with task_id '{}' and awaiting result...",
circle_name, task_id
);
info!("Script: {}", script_to_run);
match client
@@ -64,7 +67,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
task_id.clone(), // Pass the generated task_id
script_to_run.to_string(),
task_timeout,
None // public_key
None, // public_key
)
.await
{
@@ -72,7 +75,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Task {} completed successfully!", details.task_id);
debug!("Full Task Details: {:#?}", details);
// The task_id is now part of the returned RhaiTaskDetails struct.
info!("Received details for task_id: {}, script: {}", details.task_id, details.script);
info!(
"Received details for task_id: {}, script: {}",
details.task_id, details.script
);
info!("Status: {}", details.status);
if let Some(output) = details.output {
info!("Output: {}", output); // Expected: 42
@@ -110,4 +116,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Dedicated Reply Queue Demo finished.");
Ok(())
}
}

View File

@@ -57,7 +57,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
log::error!("Failed to read script file '{}': {}", script_path_str, e);
// Attempt to read from an alternative path if run via `cargo run --example`
// where current dir might be the crate root.
let alt_script_path = Path::new(file!()).parent().unwrap().join("auth_script.rhai");
let alt_script_path = Path::new(file!())
.parent()
.unwrap()
.join("auth_script.rhai");
log::info!("Attempting alternative script path: {:?}", alt_script_path);
fs::read_to_string(&alt_script_path)?
}
@@ -106,9 +109,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
);
// Basic assertion for expected output
if caller_pk == "admin_pk" {
assert_eq!(details.output, Some("Access Granted: Welcome Admin!".to_string()));
assert_eq!(
details.output,
Some("Access Granted: Welcome Admin!".to_string())
);
} else if caller_pk == "user_pk" {
assert_eq!(details.output, Some("Limited Access: Welcome User!".to_string()));
assert_eq!(
details.output,
Some("Limited Access: Welcome User!".to_string())
);
}
}
Err(e) => {

View File

@@ -2,9 +2,9 @@ use rhai::Engine;
use rhai_client::RhaiClient; // To submit tasks
use uuid::Uuid; // For generating task_id
use rhailib_worker::spawn_rhai_worker;
use std::time::Duration;
use tokio::time::sleep;
use rhailib_worker::spawn_rhai_worker;
// Custom function for Rhai
fn add(a: i64, b: i64) -> i64 {
@@ -47,26 +47,36 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
"#;
log::info!("Submitting math script to 'math_circle' and awaiting result...");
let timeout_duration = Duration::from_secs(10);
let task_id = Uuid::new_v4().to_string();
match client.submit_script_and_await_result(
"math_circle",
script_content.to_string(),
task_id, // Pass the generated task_id
timeout_duration,
None
).await {
match client
.submit_script_and_await_result(
"math_circle",
script_content.to_string(),
task_id, // Pass the generated task_id
timeout_duration,
None,
)
.await
{
Ok(details) => {
log::info!("Math Worker Example: Task finished. Status: {}, Output: {:?}, Error: {:?}",
details.status, details.output, details.error);
log::info!(
"Math Worker Example: Task finished. Status: {}, Output: {:?}, Error: {:?}",
details.status,
details.output,
details.error
);
if details.status == "completed" {
assert_eq!(details.output, Some("42".to_string()));
log::info!("Math Worker Example: Assertion for output 42 passed!");
Ok(())
} else {
log::error!("Math Worker Example: Task completed with error: {:?}", details.error);
log::error!(
"Math Worker Example: Task completed with error: {:?}",
details.error
);
Err(format!("Task failed with error: {:?}", details.error).into())
}
}
@@ -75,4 +85,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Err(e.into())
}
}
}
}

View File

@@ -2,9 +2,9 @@ use rhai::Engine;
use rhai_client::RhaiClient; // To submit tasks
use uuid::Uuid; // For generating task_id
use rhailib_worker::spawn_rhai_worker;
use std::time::Duration;
use tokio::time::sleep;
use rhailib_worker::spawn_rhai_worker;
// Custom function for Rhai
fn reverse_string(s: String) -> String {
@@ -51,22 +51,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let timeout_duration = Duration::from_secs(10);
let task_id = Uuid::new_v4().to_string();
match client.submit_script_and_await_result(
"string_circle",
script_content.to_string(),
task_id, // Pass the generated task_id
timeout_duration,
None
).await {
match client
.submit_script_and_await_result(
"string_circle",
script_content.to_string(),
task_id, // Pass the generated task_id
timeout_duration,
None,
)
.await
{
Ok(details) => {
log::info!("String Worker Example: Task finished. Status: {}, Output: {:?}, Error: {:?}",
details.status, details.output, details.error);
log::info!(
"String Worker Example: Task finished. Status: {}, Output: {:?}, Error: {:?}",
details.status,
details.output,
details.error
);
if details.status == "completed" {
assert_eq!(details.output, Some("dlrow olleh".to_string()));
log::info!("String Worker Example: Assertion for output \"dlrow olleh\" passed!");
Ok(())
} else {
log::error!("String Worker Example: Task completed with error: {:?}", details.error);
log::error!(
"String Worker Example: Task completed with error: {:?}",
details.error
);
Err(format!("Task failed with error: {:?}", details.error).into())
}
}
@@ -75,4 +85,4 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Err(e.into())
}
}
}
}