#![allow(clippy::unwrap_used)]
#![allow(clippy::clone_on_ref_ptr)]
#![allow(clippy::expect_used)]
use duroxide::providers::sqlite::SqliteProvider;
use duroxide::runtime::registry::ActivityRegistry;
use duroxide::runtime::{self};
use duroxide::{ActivityContext, Client, OrchestrationContext, OrchestrationRegistry};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let temp_dir = tempfile::tempdir()?;
let db_path = temp_dir.path().join("hello_world.db");
std::fs::File::create(&db_path)?;
let db_url = format!("sqlite:{}", db_path.to_str().unwrap());
let store = Arc::new(SqliteProvider::new(&db_url, None).await?);
let activities = ActivityRegistry::builder()
.register("Greet", |ctx: ActivityContext, name: String| async move {
ctx.trace_info(format!("Greeting user: {name}"));
Ok(format!("Hello, {name}!"))
})
.build();
let orchestration = |ctx: OrchestrationContext, name: String| async move {
ctx.trace_info("Starting greeting orchestration");
let greeting = ctx.schedule_activity("Greet", name).await?;
ctx.trace_info(format!("Greeting completed: {greeting}"));
Ok(greeting)
};
let orchestrations = OrchestrationRegistry::builder()
.register("HelloWorld", orchestration)
.build();
let rt = runtime::Runtime::start_with_store(store.clone(), activities, orchestrations).await;
let client = Client::new(store);
let instance_id = "hello-instance-1";
client
.start_orchestration(instance_id, "HelloWorld", "Rust Developer")
.await?;
match client
.wait_for_orchestration(instance_id, std::time::Duration::from_secs(10))
.await
.map_err(|e| format!("Wait error: {e:?}"))?
{
duroxide::OrchestrationStatus::Completed { output, .. } => {
println!("✅ Orchestration completed successfully!");
println!("Result: {output}");
}
duroxide::OrchestrationStatus::Failed { details, .. } => {
println!("❌ Orchestration failed: {}", details.display_message());
}
_ => {
println!("⏳ Orchestration still running or in unexpected state");
}
}
rt.shutdown(None).await;
Ok(())
}