- Simplified RunnerConfig to just name, command, and optional env - Removed RunnerType and ProcessManagerType enums - Removed db_path, redis_url, binary_path from config - Made runner name also serve as queue name (no separate queue param) - Added secret-based authentication to all runner management methods - Created comprehensive osiris_openrpc example - Archived old examples to _archive/ - Updated client API to match simplified supervisor interface
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
//! Simple job workflow example
 | 
						|
//! 
 | 
						|
//! This example demonstrates the basic job lifecycle using the new API:
 | 
						|
//! 1. Create a job
 | 
						|
//! 2. Start the job
 | 
						|
//! 3. Monitor its progress
 | 
						|
//! 4. Get the result
 | 
						|
 | 
						|
use hero_supervisor_openrpc_client::{SupervisorClient, JobBuilder, JobResult};
 | 
						|
use std::time::Duration;
 | 
						|
use tokio::time::sleep;
 | 
						|
 | 
						|
#[tokio::main]
 | 
						|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
 | 
						|
    println!("Simple Job Workflow Example");
 | 
						|
    println!("============================\n");
 | 
						|
 | 
						|
    // Create client
 | 
						|
    let client = SupervisorClient::new("http://localhost:3030")?;
 | 
						|
    let secret = "user-secret-456";
 | 
						|
 | 
						|
    // Create a simple job
 | 
						|
    let job = JobBuilder::new()
 | 
						|
        .caller_id("simple_example")
 | 
						|
        .context_id("demo")
 | 
						|
        .payload("echo 'Hello from Hero Supervisor!' && sleep 3 && echo 'Job completed!'")
 | 
						|
        .executor("osis")
 | 
						|
        .runner("osis_runner_1")
 | 
						|
        .timeout(60)
 | 
						|
        .env_var("EXAMPLE_VAR", "example_value")
 | 
						|
        .build()?;
 | 
						|
 | 
						|
    println!("📝 Creating job...");
 | 
						|
    let job_id = client.jobs_create(secret, job).await?;
 | 
						|
    println!("✅ Job created: {}\n", job_id);
 | 
						|
 | 
						|
    println!("🚀 Starting job...");
 | 
						|
    client.job_start(secret, &job_id).await?;
 | 
						|
    println!("✅ Job started\n");
 | 
						|
 | 
						|
    println!("👀 Monitoring job progress...");
 | 
						|
    loop {
 | 
						|
        let status = client.job_status(&job_id).await?;
 | 
						|
        println!("   Status: {}", status.status);
 | 
						|
        
 | 
						|
        if status.status == "completed" || status.status == "failed" {
 | 
						|
            break;
 | 
						|
        }
 | 
						|
        
 | 
						|
        sleep(Duration::from_secs(2)).await;
 | 
						|
    }
 | 
						|
 | 
						|
    println!("\n📋 Getting job result...");
 | 
						|
    match client.job_result(&job_id).await? {
 | 
						|
        JobResult::Success { success } => {
 | 
						|
            println!("✅ Success: {}", success);
 | 
						|
        },
 | 
						|
        JobResult::Error { error } => {
 | 
						|
            println!("❌ Error: {}", error);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    Ok(())
 | 
						|
}
 |