1use async_trait::async_trait;
7use std::time::Duration;
8
9pub const DEFAULT_EPOCH_DURATION: Duration = Duration::from_secs(30);
11
12pub struct StewardSchedulerConfig {
14 pub epoch_interval: Duration,
16}
17
18impl Default for StewardSchedulerConfig {
19 fn default() -> Self {
20 Self {
21 epoch_interval: DEFAULT_EPOCH_DURATION,
22 }
23 }
24}
25
26#[async_trait]
30pub trait StewardScheduler: Send + Sync {
31 async fn next_tick(&mut self);
33}
34
35pub struct IntervalScheduler {
37 interval: tokio::time::Interval,
38}
39
40impl IntervalScheduler {
41 pub fn new(config: StewardSchedulerConfig) -> Self {
42 Self {
43 interval: tokio::time::interval(config.epoch_interval),
44 }
45 }
46}
47
48#[async_trait]
49impl StewardScheduler for IntervalScheduler {
50 async fn next_tick(&mut self) {
51 self.interval.tick().await;
52 }
53}