floxide_core/distributed/
error_store.rs1use crate::distributed::{ErrorStoreError, WorkflowError};
7use async_trait::async_trait;
8use std::collections::HashMap;
9use std::sync::Arc;
10use tokio::sync::Mutex;
11
12#[async_trait]
16pub trait ErrorStore {
17 async fn record_error(&self, run_id: &str, error: WorkflowError)
19 -> Result<(), ErrorStoreError>;
20 async fn get_errors(&self, run_id: &str) -> Result<Vec<WorkflowError>, ErrorStoreError>;
22}
23
24#[derive(Clone, Default)]
26pub struct InMemoryErrorStore {
27 inner: Arc<Mutex<HashMap<String, Vec<WorkflowError>>>>,
28}
29
30#[async_trait]
31impl ErrorStore for InMemoryErrorStore {
32 async fn record_error(
33 &self,
34 run_id: &str,
35 error: WorkflowError,
36 ) -> Result<(), ErrorStoreError> {
37 let mut map = self.inner.lock().await;
38 map.entry(run_id.to_string()).or_default().push(error);
39 Ok(())
40 }
41 async fn get_errors(&self, run_id: &str) -> Result<Vec<WorkflowError>, ErrorStoreError> {
42 let map = self.inner.lock().await;
43 Ok(map.get(run_id).cloned().unwrap_or_default())
44 }
45}