use super::ProviderError;
use crate::Event;
#[async_trait::async_trait]
pub trait ManagementProvider: Send + Sync {
async fn list_instances(&self) -> Result<Vec<String>, ProviderError> {
Ok(Vec::new())
}
async fn list_instances_by_status(&self, _status: &str) -> Result<Vec<String>, ProviderError> {
Ok(Vec::new())
}
async fn list_executions(&self, _instance: &str) -> Result<Vec<u64>, ProviderError> {
Ok(vec![1])
}
async fn read_execution(&self, instance: &str, _execution_id: u64) -> Result<Vec<Event>, ProviderError> {
Err(ProviderError::permanent(
"read_execution",
format!("not supported for instance: {instance}"),
))
}
async fn latest_execution_id(&self, _instance: &str) -> Result<u64, ProviderError> {
Ok(1)
}
async fn get_instance_info(&self, instance: &str) -> Result<InstanceInfo, ProviderError> {
Err(ProviderError::permanent(
"get_instance_info",
format!("not supported for instance: {instance}"),
))
}
async fn get_execution_info(&self, instance: &str, _execution_id: u64) -> Result<ExecutionInfo, ProviderError> {
Err(ProviderError::permanent(
"get_execution_info",
format!("not supported for instance: {instance}"),
))
}
async fn get_system_metrics(&self) -> Result<SystemMetrics, ProviderError> {
Ok(SystemMetrics::default())
}
async fn get_queue_depths(&self) -> Result<QueueDepths, ProviderError> {
Ok(QueueDepths::default())
}
}
#[derive(Debug, Clone)]
pub struct InstanceInfo {
pub instance_id: String,
pub orchestration_name: String,
pub orchestration_version: String,
pub current_execution_id: u64,
pub status: String, pub output: Option<String>, pub created_at: u64, pub updated_at: u64,
pub parent_instance_id: Option<String>, }
#[derive(Debug, Clone)]
pub struct ExecutionInfo {
pub execution_id: u64,
pub status: String, pub output: Option<String>, pub started_at: u64, pub completed_at: Option<u64>, pub event_count: usize, }
#[derive(Debug, Clone, Default)]
pub struct SystemMetrics {
pub total_instances: u64,
pub total_executions: u64,
pub running_instances: u64,
pub completed_instances: u64,
pub failed_instances: u64,
pub total_events: u64,
}
#[derive(Debug, Clone, Default)]
pub struct QueueDepths {
pub orchestrator_queue: usize, pub worker_queue: usize, pub timer_queue: usize, }
#[derive(Debug, Clone, Default)]
pub struct InstanceFilter {
pub instance_ids: Option<Vec<String>>,
pub completed_before: Option<u64>,
pub limit: Option<u32>,
}
#[derive(Debug, Clone, Default)]
pub struct PruneOptions {
pub keep_last: Option<u32>,
pub completed_before: Option<u64>,
}
#[derive(Debug, Clone, Default)]
pub struct DeleteInstanceResult {
pub instances_deleted: u64,
pub executions_deleted: u64,
pub events_deleted: u64,
pub queue_messages_deleted: u64,
}
#[derive(Debug, Clone, Default)]
pub struct PruneResult {
pub instances_processed: u64,
pub executions_deleted: u64,
pub events_deleted: u64,
}
#[derive(Debug, Clone)]
pub struct InstanceTree {
pub root_id: String,
pub all_ids: Vec<String>,
}
impl InstanceTree {
pub fn is_root_only(&self) -> bool {
self.all_ids.len() == 1
}
pub fn size(&self) -> usize {
self.all_ids.len()
}
}