wip
This commit is contained in:
		@@ -8,7 +8,7 @@ name = "supervisor_worker_demo"
 | 
			
		||||
path = "supervisor_worker_demo.rs"
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
hero_dispatcher = { path = "../dispatcher" }
 | 
			
		||||
hero_supervisor = { path = "../supervisor" }
 | 
			
		||||
hero_job = { path = "../job" }
 | 
			
		||||
tokio = { version = "1.0", features = ["full"] }
 | 
			
		||||
redis = { version = "0.25", features = ["tokio-comp"] }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
use colored::*;
 | 
			
		||||
use hero_dispatcher::{DispatcherBuilder, ScriptType, JobStatus};
 | 
			
		||||
use hero_supervisor::{SupervisorBuilder, ScriptType, JobStatus};
 | 
			
		||||
use log::warn;
 | 
			
		||||
use std::process::Stdio;
 | 
			
		||||
use std::time::Duration;
 | 
			
		||||
@@ -8,7 +8,7 @@ use tokio::time::sleep;
 | 
			
		||||
 | 
			
		||||
/// Supervisor manages worker lifecycle and job execution
 | 
			
		||||
pub struct Supervisor {
 | 
			
		||||
    dispatcher: hero_dispatcher::Dispatcher,
 | 
			
		||||
    supervisor: hero_supervisor::Supervisor,
 | 
			
		||||
    worker_processes: Vec<WorkerProcess>,
 | 
			
		||||
    redis_url: String,
 | 
			
		||||
}
 | 
			
		||||
@@ -22,9 +22,9 @@ pub struct WorkerProcess {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Supervisor {
 | 
			
		||||
    /// Create a new supervisor with dispatcher configuration
 | 
			
		||||
    /// Create a new supervisor with supervisor configuration
 | 
			
		||||
    pub async fn new(redis_url: String) -> Result<Self, Box<dyn std::error::Error>> {
 | 
			
		||||
        let dispatcher = DispatcherBuilder::new()
 | 
			
		||||
        let supervisor = SupervisorBuilder::new()
 | 
			
		||||
            .caller_id("supervisor")
 | 
			
		||||
            .context_id("demo-context")
 | 
			
		||||
            .redis_url(&redis_url)
 | 
			
		||||
@@ -34,7 +34,7 @@ impl Supervisor {
 | 
			
		||||
            .build()?;
 | 
			
		||||
 | 
			
		||||
        Ok(Self {
 | 
			
		||||
            dispatcher,
 | 
			
		||||
            supervisor,
 | 
			
		||||
            worker_processes: Vec::new(),
 | 
			
		||||
            redis_url,
 | 
			
		||||
        })
 | 
			
		||||
@@ -109,7 +109,7 @@ impl Supervisor {
 | 
			
		||||
 | 
			
		||||
    /// Submit a job and return the job ID
 | 
			
		||||
    pub async fn submit_job(&self, script_type: ScriptType, script: &str) -> Result<String, Box<dyn std::error::Error>> {
 | 
			
		||||
        let job = self.dispatcher
 | 
			
		||||
        let job = self.supervisor
 | 
			
		||||
            .new_job()
 | 
			
		||||
            .script_type(script_type.clone())
 | 
			
		||||
            .script(script)
 | 
			
		||||
@@ -117,7 +117,7 @@ impl Supervisor {
 | 
			
		||||
            .build()?;
 | 
			
		||||
 | 
			
		||||
        let job_id = job.id.clone();
 | 
			
		||||
        self.dispatcher.create_job(&job).await?;
 | 
			
		||||
        self.supervisor.create_job(&job).await?;
 | 
			
		||||
        
 | 
			
		||||
        println!("{}", format!("📝 Job {} submitted for {}", job_id, script_type.as_str()).cyan());
 | 
			
		||||
        Ok(job_id)
 | 
			
		||||
@@ -134,12 +134,12 @@ impl Supervisor {
 | 
			
		||||
                return Err("Job execution timeout".into());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Check job status using dispatcher methods
 | 
			
		||||
            match self.dispatcher.get_job_status(job_id).await {
 | 
			
		||||
            // Check job status using supervisor methods
 | 
			
		||||
            match self.supervisor.get_job_status(job_id).await {
 | 
			
		||||
                Ok(status) => {
 | 
			
		||||
                    match status {
 | 
			
		||||
                        JobStatus::Finished => {
 | 
			
		||||
                            if let Ok(Some(result)) = self.dispatcher.get_job_output(job_id).await {
 | 
			
		||||
                            if let Ok(Some(result)) = self.supervisor.get_job_output(job_id).await {
 | 
			
		||||
                                println!("{}", format!("✅ Job {} completed successfully", job_id).green());
 | 
			
		||||
                                return Ok(result);
 | 
			
		||||
                            }
 | 
			
		||||
@@ -163,12 +163,12 @@ impl Supervisor {
 | 
			
		||||
 | 
			
		||||
    /// List all jobs
 | 
			
		||||
    pub async fn list_jobs(&self) -> Result<Vec<String>, Box<dyn std::error::Error>> {
 | 
			
		||||
        self.dispatcher.list_jobs().await.map_err(|e| e.into())
 | 
			
		||||
        self.supervisor.list_jobs().await.map_err(|e| e.into())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Clear all jobs
 | 
			
		||||
    pub async fn clear_all_jobs(&self) -> Result<usize, Box<dyn std::error::Error>> {
 | 
			
		||||
        self.dispatcher.clear_all_jobs().await.map_err(|e| e.into())
 | 
			
		||||
        self.supervisor.clear_all_jobs().await.map_err(|e| e.into())
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Get worker status
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user