use crate::types::{ActionId, BuildEvent, BuildRecord};
use async_trait::async_trait;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum CacheError {
#[error("io: {0}")]
Io(#[from] std::io::Error),
#[error("backend: {0}")]
Backend(String),
}
pub type Result<T> = std::result::Result<T, CacheError>;
#[async_trait]
pub trait Cache: Send + Sync {
async fn last_build(&self, id: &ActionId) -> Option<BuildEvent>;
async fn last_record(&self, id: &ActionId) -> Option<BuildRecord> {
self.last_build(id).await.map(|event| BuildRecord {
event,
recorded_at: None,
})
}
async fn record(&mut self, event: BuildEvent) -> Result<()>;
async fn record_batch(&mut self, events: Vec<BuildEvent>) -> Result<()> {
for event in events {
self.record(event).await?;
}
Ok(())
}
}