General code improvements

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet
2025-08-22 12:48:36 +02:00
parent 74995fa6fe
commit bc6cb16732
4 changed files with 32 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
use crate::dag::{build_flow_dag, DagResult, FlowDag};
use crate::dag::{DagResult, FlowDag, build_flow_dag};
use crate::models::{Actor, Context, Flow, Job, JobStatus, Message, Runner};
use crate::storage::RedisDriver;
@@ -95,17 +95,24 @@ impl AppService {
Ok(job)
}
pub async fn load_job(&self, context_id: u32, caller_id: u32, id: u32) -> Result<Job, BoxError> {
pub async fn load_job(
&self,
context_id: u32,
caller_id: u32,
id: u32,
) -> Result<Job, BoxError> {
let job = self.redis.load_job(context_id, caller_id, id).await?;
Ok(job)
}
/// Update a job status with transition validation.
///
/// Allowed transitions:
/// - Dispatched -> WaitingForPrerequisites | Started | Error
/// - WaitingForPrerequisites -> Started | Error
/// - Started -> Finished | Error
/// - Finished, Error -> terminal (no transitions)
///
/// If the new status equals the current status, this is a no-op.
pub async fn update_job_status(
&self,
@@ -127,14 +134,10 @@ impl AppService {
new_status,
JobStatus::WaitingForPrerequisites | JobStatus::Started | JobStatus::Error
),
JobStatus::WaitingForPrerequisites => matches!(
new_status,
JobStatus::Started | JobStatus::Error
),
JobStatus::Started => matches!(
new_status,
JobStatus::Finished | JobStatus::Error
),
JobStatus::WaitingForPrerequisites => {
matches!(new_status, JobStatus::Started | JobStatus::Error)
}
JobStatus::Started => matches!(new_status, JobStatus::Finished | JobStatus::Error),
JobStatus::Finished | JobStatus::Error => false,
};
@@ -153,13 +156,23 @@ impl AppService {
// -----------------------------
// Message
// -----------------------------
pub async fn create_message(&self, context_id: u32, message: Message) -> Result<Message, BoxError> {
pub async fn create_message(
&self,
context_id: u32,
message: Message,
) -> Result<Message, BoxError> {
self.redis.save_message(context_id, &message).await?;
Ok(message)
}
pub async fn load_message(&self, context_id: u32, caller_id: u32, id: u32) -> Result<Message, BoxError> {
pub async fn load_message(
&self,
context_id: u32,
caller_id: u32,
id: u32,
) -> Result<Message, BoxError> {
let msg = self.redis.load_message(context_id, caller_id, id).await?;
Ok(msg)
}
}
}