use async_trait::async_trait;
use futures::Stream;
use ora_common::task::{TaskDataFormat, TaskDefinition, WorkerSelector};
use uuid::Uuid;
#[async_trait]
pub trait WorkerStore: Send + Sync + Clone {
type Error: std::error::Error + Send + Sync + 'static;
type Events: Stream<Item = Result<WorkerStoreEvent, Self::Error>>;
async fn events(&self, selectors: &[WorkerSelector]) -> Result<Self::Events, Self::Error>;
async fn ready_tasks(
&self,
selectors: &[WorkerSelector],
) -> Result<Vec<ReadyTask>, Self::Error>;
async fn select_task(&self, task_id: Uuid, worker_id: Uuid) -> Result<bool, Self::Error>;
async fn task_started(&self, task_id: Uuid) -> Result<(), Self::Error>;
async fn task_succeeded(
&self,
task_id: Uuid,
output: Vec<u8>,
output_format: TaskDataFormat,
) -> Result<(), Self::Error>;
async fn task_failed(&self, task_id: Uuid, reason: String) -> Result<(), Self::Error>;
async fn task_cancelled(&self, task_id: Uuid) -> Result<(), Self::Error>;
}
#[derive(Debug, Clone)]
pub struct ReadyTask {
pub id: Uuid,
pub definition: TaskDefinition,
}
#[derive(Debug, Clone)]
pub enum WorkerStoreEvent {
TaskReady(ReadyTask),
TaskCancelled(Uuid),
}