runtasktic 1.2.1

Command-line task management tool for execution of regular long sequential or parallel tasks.
Documentation
use chrono::Local;
use cron::Schedule;

pub trait WaitSchedule<T> {
  fn wait(&self, timezone: T);
}

impl WaitSchedule<Local> for Option<Schedule> {
  fn wait(&self, timezone: Local) {
    if let Some(cron) = self {
      cron.wait(timezone);
    }
  }
}

impl WaitSchedule<Local> for Schedule {
  fn wait(&self, timezone: Local) {
    let date = self
      .upcoming(timezone)
      .next()
      .expect("Cannot get upcoming cron date");
    debug!("Schedule wait until {date}");
    std::thread::sleep(
      (date - Local::now())
        .to_std()
        .expect("Cannot transform Duration"),
    );
  }
}