end to end job management support

This commit is contained in:
Timur Gordon
2025-07-30 08:36:55 +02:00
parent 7d7ff0f0ab
commit 32c2cbe0cc
20 changed files with 2686 additions and 442 deletions

View File

@@ -19,6 +19,8 @@ pub enum DispatcherError {
ContextIdMissing,
/// Invalid input provided
InvalidInput(String),
/// Job operation error
JobError(hero_job::JobError),
}
impl From<redis::RedisError> for DispatcherError {
@@ -33,6 +35,12 @@ impl From<serde_json::Error> for DispatcherError {
}
}
impl From<hero_job::JobError> for DispatcherError {
fn from(err: hero_job::JobError) -> Self {
DispatcherError::JobError(err)
}
}
impl std::fmt::Display for DispatcherError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
@@ -50,6 +58,9 @@ impl std::fmt::Display for DispatcherError {
DispatcherError::InvalidInput(msg) => {
write!(f, "Invalid input: {}", msg)
}
DispatcherError::JobError(e) => {
write!(f, "Job error: {}", e)
}
}
}
}

View File

@@ -11,6 +11,7 @@ pub use crate::job::JobBuilder;
// Re-export types from hero_job for public API
pub use hero_job::{Job, JobStatus, ScriptType};
#[derive(Clone)]
pub struct Dispatcher {
redis_client: redis::Client,
caller_id: String,
@@ -218,6 +219,23 @@ impl Dispatcher {
Ok(())
}
// Method to start a previously created job
pub async fn start_job(
&self,
job_id: &str,
) -> Result<(), DispatcherError> {
let mut conn = self.redis_client.get_multiplexed_async_connection().await?;
// Load the job to get its script type
let job = Job::load_from_redis(&mut conn, job_id).await?;
// Select worker based on script type
let worker_id = self.select_worker_for_script_type(&job.script_type)?;
self.start_job_using_connection(&mut conn, job_id.to_string(), worker_id).await?;
Ok(())
}
// New method using dedicated reply queue with automatic worker selection
pub async fn run_job_and_await_result(
&self,