add support for auth and other improvements

This commit is contained in:
timurgordon
2025-06-19 01:42:02 +03:00
parent de1740f0d1
commit 4e717bc054
33 changed files with 433 additions and 864 deletions

View File

@@ -1,10 +1,10 @@
use log::{info, error, debug};
use rhai::Engine;
use rhai_client::{RhaiClient, RhaiClientError}; // RhaiTaskDetails is not directly used
use worker_lib::spawn_rhai_worker;
use rhai_client::{RhaiClient, RhaiClientError}; // RhaiTaskDetails is now used for its fields
use rhailib_worker::spawn_rhai_worker;
use std::time::Duration;
use tokio::sync::mpsc;
use serde_json::Value;
use uuid::Uuid; // Added for generating task_id
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -53,28 +53,26 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 5. Submit script and await result using the new mechanism
let task_timeout = Duration::from_secs(10);
let client_rpc_id: Option<Value> = Some(serde_json::json!({ "demo_request_id": "reply_queue_test_001" }));
let task_id = Uuid::new_v4().to_string(); // Generate a unique task_id
info!("Submitting script to circle '{}' and awaiting result...", circle_name);
info!("Submitting script to circle '{}' with task_id '{}' and awaiting result...", circle_name, task_id);
info!("Script: {}", script_to_run);
match client
.submit_script_and_await_result(
circle_name,
task_id.clone(), // Pass the generated task_id
script_to_run.to_string(),
client_rpc_id,
task_timeout,
// poll_interval is no longer needed
None // public_key
)
.await
{
Ok(details) => {
info!("Task completed successfully!");
info!("Task {} completed successfully!", details.task_id);
debug!("Full Task Details: {:#?}", details);
// The task_id is not part of the returned RhaiTaskDetails struct.
// We could modify the client to return (task_id, details) if needed,
// but for this demo, we'll just log the content of the returned details.
info!("Received details for script: {}", details.script);
// The task_id is now part of the returned RhaiTaskDetails struct.
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
@@ -89,7 +87,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Err(e) => {
error!("An error occurred while awaiting task result: {}", e);
// The specific error can be inspected if needed, e.g., for timeout
if let RhaiClientError::Timeout(task_id) = e {
if let RhaiClientError::Timeout(returned_task_id) = e {
// Note: 'task_id' here is the one from the error, which should match the one we sent.
info!("Task {} timed out.", returned_task_id);
info!("Task {} timed out.", task_id);
}
}