use crate::model::{ProcessDefinition, ProcessInstance, Token};
pub trait ProcessInstanceRepo {
fn load(&self, id: &str) -> Option<ProcessInstance>;
fn save(&self, instance: &ProcessInstance);
fn list_running(&self) -> Vec<String>;
}
pub trait TokenRepo {
fn load_by_instance(&self, instance_id: &str) -> Vec<Token>;
fn save_tokens(&self, instance_id: &str, tokens: &[Token]);
fn update_token_cas(&self, instance_id: &str, token: &Token) -> bool;
fn claim_token(&self, instance_id: &str, token_id: &str, version: u32) -> bool;
}
pub trait ProcessDefinitionRepo {
fn load(&self, id: &str) -> Option<ProcessDefinition>;
}
pub trait UserTaskRepo {
fn complete(&self, _task_id: &str) {}
}
#[derive(Debug, Clone)]
pub struct OutboxEvent {
pub id: String,
pub event_type: String,
pub payload: String,
pub status: String, pub created_at: Option<String>,
}
pub trait ParallelJoinRepo {
fn ensure_group(&self, group_id: &str, expected: u32) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
fn try_join(&self, group_id: &str) -> Result<bool, Box<dyn std::error::Error + Send + Sync>>;
}
pub trait OutboxRepo {
fn insert_pending(&self, event_type: &str, payload: &str) -> Result<String, Box<dyn std::error::Error + Send + Sync>>;
fn list_pending(&self) -> Result<Vec<OutboxEvent>, Box<dyn std::error::Error + Send + Sync>>;
fn mark_published(&self, id: &str) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
}
#[derive(Debug, Clone)]
pub struct TimerRecord {
pub id: String,
pub token_id: String,
pub instance_id: String,
pub due_at: String,
pub status: String, pub created_at: String,
}
pub trait TimerRepo {
fn get_by_id(&self, id: &str) -> Option<TimerRecord>;
fn mark_fired(&self, id: &str) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
fn insert(&self, record: &TimerRecord) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
}
#[derive(Debug, Clone)]
pub struct CompensationRecordRow {
pub id: String,
pub instance_id: String,
pub node_id: String,
pub handler_ref: String,
pub order: u32,
pub status: String, pub created_at: String,
}
pub trait CompensationRecordRepo {
fn add(&self, record: &CompensationRecordRow) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
fn list_by_instance(&self, instance_id: &str) -> Vec<CompensationRecordRow>;
}
pub trait TransactionScope {
fn with_tx<'r, F, R>(&'r self, f: F) -> std::result::Result<R, Box<dyn std::error::Error + Send + Sync>>
where
F: FnOnce(Box<dyn ProcessInstanceRepo + 'r>, Box<dyn TokenRepo + 'r>) -> R;
}