use std::hash::Hash;
use std::sync::Arc;
use std::fmt::Debug;
use super::prelude::*;
use super::structs::HealthDetails;
pub trait ScriptTrait {
type Id: Debug + Hash + PartialEq + Eq + Send + Copy + Clone;
fn id(&self) -> Self::Id;
fn can_be_parallel(&self) -> bool;
}
pub trait ScriptsRepositoryTrait: Send + Sync {
type Script: ScriptTrait + Send + Sync;
type Job: JobTrait<Self::Script> + Debug + Send + Sync + Clone;
type ScriptsIter: Iterator<Item = Arc<Self::Script>>;
type JobsIter: Iterator<Item = Self::Job>;
fn id_exists(&self, id: &<Self::Script as ScriptTrait>::Id) -> bool;
fn iter(&self) -> Self::ScriptsIter;
fn jobs_after_output(
&self,
output: <Self::Job as JobTrait<Self::Script>>::Output,
) -> Option<Self::JobsIter>;
}
pub trait JobTrait<S: ScriptTrait> {
type Context: Debug + Send + Sync;
type Output: Clone + Send + Sync;
fn execute(&self, ctx: &Self::Context) -> Result<Self::Output>;
fn script_id(&self) -> S::Id;
fn script_name(&self) -> &str;
}
pub trait ProcessorApiTrait<S: ScriptsRepositoryTrait>: Send {
fn queue(&self, job: S::Job, priority: isize) -> Result<()>;
fn health_details(&self) -> Result<HealthDetails>;
fn cleanup(&self) -> Result<()>;
fn lock(&self) -> Result<()>;
fn unlock(&self) -> Result<()>;
}