Experiments in applying Entity-Component-System patterns to durable data storage APIs.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

schedule: initial work

moritz.vongoewels.de 8f9c6f6a 26adc858

verified
+52
+2
src/lib.rs
··· 19 19 pub mod resource; 20 20 pub use resource::*; 21 21 22 + pub mod schedule; 23 + 22 24 pub mod sqlite_ext; 23 25 24 26 pub mod system;
+50
src/schedule.rs
··· 1 + use crate::{system, Entity, System}; 2 + 3 + pub trait SchedulingMode: std::fmt::Debug { 4 + fn should_run(&self, ecs: &crate::Ecs, system: Entity) -> bool; 5 + fn did_run(&self, _ecs: &crate::Ecs, _system: Entity) {} 6 + } 7 + 8 + pub struct Schedule { 9 + pub mode: Box<dyn SchedulingMode>, 10 + pub systems: Vec<Box<dyn System>>, 11 + } 12 + 13 + #[derive(Debug)] 14 + pub struct Manually; 15 + 16 + impl SchedulingMode for Manually { 17 + fn should_run(&self, _ecs: &crate::Ecs, _system: Entity) -> bool { 18 + false 19 + } 20 + } 21 + 22 + #[derive(Debug)] 23 + pub struct Always; 24 + 25 + impl SchedulingMode for Always { 26 + fn should_run(&self, _ecs: &crate::Ecs, _system: Entity) -> bool { 27 + true 28 + } 29 + } 30 + 31 + #[derive(Debug)] 32 + pub struct Every(pub chrono::Duration); 33 + 34 + impl SchedulingMode for Every { 35 + fn should_run(&self, _ecs: &crate::Ecs, system: Entity) -> bool { 36 + system 37 + .component::<system::LastRun>() 38 + .map(|last_run| chrono::Utc::now().signed_duration_since(&last_run.0) > self.0) 39 + .unwrap_or(true) 40 + } 41 + } 42 + 43 + #[derive(Debug)] 44 + pub struct Oneshot; 45 + 46 + impl SchedulingMode for Oneshot { 47 + fn should_run(&self, _ecs: &crate::Ecs, system: Entity) -> bool { 48 + system.component::<system::LastRun>().is_none() 49 + } 50 + }