|
|
|
@ -68,9 +68,21 @@ impl DbHandle {
|
|
|
|
|
pub(crate) fn get_time_until_next_action(
|
|
|
|
|
&mut self,
|
|
|
|
|
) -> Result<Duration, Box<dyn std::error::Error>> {
|
|
|
|
|
let now = SystemTime::now()
|
|
|
|
|
.duration_since(SystemTime::UNIX_EPOCH)?
|
|
|
|
|
.as_secs();
|
|
|
|
|
todo!()
|
|
|
|
|
let now = SystemTime::now();
|
|
|
|
|
let mut stmt = self.conn.prepare(
|
|
|
|
|
"WITH next_runs AS (SELECT next_run FROM global_action UNION SELECT next_run FROM local_action) SELECT next_run FROM next_runs ORDER BY next_run ASC",
|
|
|
|
|
)?;
|
|
|
|
|
let rows = stmt
|
|
|
|
|
.query_map(params![], |row| Ok(row.get(0)?))?
|
|
|
|
|
.collect::<Result<Vec<u64>, _>>()?;
|
|
|
|
|
if let Some(r) = rows.into_iter().next() {
|
|
|
|
|
let next_run = SystemTime::UNIX_EPOCH + Duration::from_secs(r);
|
|
|
|
|
if next_run <= now {
|
|
|
|
|
return Ok(Duration::from_secs(0));
|
|
|
|
|
} else {
|
|
|
|
|
return Ok(next_run.duration_since(now)?);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Ok(Duration::from_secs(0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|