mod event;
mod memory;
pub mod contract_tests;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
pub use contract_tests::store_conformance_suite;
pub use event::{StoreEvent, StoreEventStream};
pub use memory::InMemoryStore;
use super::error::StoreError;
use super::model::{
DispatchTicket, Job, JobId, LogRange, PipelineId, PipelineSpec, Run, RunId, TerminalOutcome,
};
#[async_trait]
pub trait Store: Send + Sync + 'static {
async fn put_pipeline(&self, spec: PipelineSpec) -> Result<(), StoreError>;
async fn get_pipeline(&self, id: PipelineId) -> Result<Option<PipelineSpec>, StoreError>;
async fn create_run(
&self,
pipeline: PipelineId,
inputs: serde_json::Value,
) -> Result<RunId, StoreError>;
async fn next_dispatchable(&self, kinds: &[String]) -> Result<Option<Job>, StoreError>;
async fn try_dispatch(
&self,
job_id: JobId,
max_concurrent_for_kind: usize,
) -> Result<Option<DispatchTicket>, StoreError>;
async fn set_pid(&self, job_id: JobId, pid: u32) -> Result<(), StoreError>;
async fn complete_job_and_propagate(
&self,
ticket: DispatchTicket,
terminal: TerminalOutcome,
) -> Result<bool, StoreError>;
async fn cancel_run(&self, run_id: RunId) -> Result<(), StoreError>;
async fn append_log(&self, job_id: JobId, line: &str) -> Result<(), StoreError>;
async fn read_log(&self, job_id: JobId, range: LogRange) -> Result<Vec<String>, StoreError>;
async fn get_job(&self, job_id: JobId) -> Result<Option<Job>, StoreError>;
async fn get_run(&self, run_id: RunId) -> Result<Option<Run>, StoreError>;
async fn list_run_jobs(&self, run_id: RunId) -> Result<Vec<Job>, StoreError>;
async fn subscribe(&self) -> StoreEventStream;
async fn find_running_past(
&self,
deadline: DateTime<Utc>,
) -> Result<Vec<DispatchTicket>, StoreError>;
async fn find_cancelled_with_pid(&self) -> Result<Vec<(JobId, u32)>, StoreError>;
async fn clear_pid_and_kill_flag(&self, job_id: JobId) -> Result<(), StoreError>;
}