mod scope;
mod task;
pub use scope::*;
pub use task::*;
use crate::storage::{CountedByKey, KeyIterableByKeyMap, ValueStorage};
use core::fmt::Debug;
pub trait Scheduler {
type BlockNumber;
type Task;
type Cost;
type Error: TaskPoolError;
type OutputError: From<Self::Error> + Debug;
type CostsPerBlock: SchedulingCostsPerBlock<BlockNumber = Self::BlockNumber, Cost = Self::Cost>;
type FirstIncompleteTasksBlock: ValueStorage<Value = Self::BlockNumber>;
type TaskPool: TaskPool<
BlockNumber = Self::BlockNumber,
Task = Self::Task,
Error = Self::Error,
OutputError = Self::OutputError,
> + CountedByKey<Key = Self::BlockNumber, Length = usize>
+ KeyIterableByKeyMap<Key1 = Self::BlockNumber, Key2 = Self::Task>;
fn reset() {
Self::FirstIncompleteTasksBlock::kill();
Self::TaskPool::clear();
}
}
pub trait SchedulingCostsPerBlock {
type BlockNumber;
type Cost;
fn reserve_for() -> Self::BlockNumber;
fn code() -> Self::Cost;
fn mailbox() -> Self::Cost;
fn program() -> Self::Cost;
fn waitlist() -> Self::Cost;
fn reservation() -> Self::Cost;
fn dispatch_stash() -> Self::Cost;
fn by_storage_type(storage: StorageType) -> Self::Cost;
}
#[derive(Debug, Clone, Copy)]
pub enum StorageType {
Code,
Mailbox,
Program,
Waitlist,
Reservation,
DispatchStash,
}