(
&mut self,
script_timer: IntervalTimerContrib,
db_timer: Option<&IntervalTimer>,
)
| 173 | } |
| 174 | |
| 175 | async fn init_timer( |
| 176 | &mut self, |
| 177 | script_timer: IntervalTimerContrib, |
| 178 | db_timer: Option<&IntervalTimer>, |
| 179 | ) -> Result<(), anyhow::Error> { |
| 180 | let last_run = db_timer |
| 181 | .map(|v| v.last_run) |
| 182 | .unwrap_or_else(chrono::Utc::now); |
| 183 | |
| 184 | let timer = self |
| 185 | .storage |
| 186 | .update_interval_timer( |
| 187 | self.guild_id, |
| 188 | IntervalTimer { |
| 189 | last_run, |
| 190 | interval: script_timer.interval, |
| 191 | name: script_timer.name, |
| 192 | plugin_id: script_timer.plugin_id, |
| 193 | }, |
| 194 | ) |
| 195 | .await?; |
| 196 | |
| 197 | match wrap_timer(timer) { |
| 198 | Ok(wrapped) => { |
| 199 | self.loaded_intervals.insert( |
| 200 | TimerId(wrapped.inner.plugin_id, wrapped.inner.name.clone()), |
| 201 | wrapped, |
| 202 | ); |
| 203 | } |
| 204 | Err(err) => tracing::error!(?err, "failed wrapping timer"), |
| 205 | }; |
| 206 | |
| 207 | Ok(()) |
| 208 | } |
| 209 | |
| 210 | pub fn next_event_time(&self) -> Option<DateTime<Utc>> { |
| 211 | let lowest_interval = self |
no test coverage detected