From 2b018dedeec4bcebf7d34ecfb47c6167e8c7f6ef Mon Sep 17 00:00:00 2001 From: Maria Kuklina <101095419+kmd-fl@users.noreply.github.com> Date: Thu, 26 Jan 2023 12:21:13 +0100 Subject: [PATCH] fix(spells): correct interpretation of end_sec field [NET-346] (#1431) fix spell rescheduling --- crates/spell-event-bus/src/bus.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/spell-event-bus/src/bus.rs b/crates/spell-event-bus/src/bus.rs index c50e703b54..251f20dcc4 100644 --- a/crates/spell-event-bus/src/bus.rs +++ b/crates/spell-event-bus/src/bus.rs @@ -69,12 +69,12 @@ impl Scheduled { /// Reschedule a spell to `now` + `period`. /// Return `None` if the spell is supposed to end at the given time `end_at`. fn at(data: Periodic, now: Instant) -> Option { - if data.end_at.map(|end_at| end_at <= now).unwrap_or(false) { + // We do checked_add here only to avoid a mere possibility of internal panic. + let run_at = now.checked_add(data.period)?; + if data.end_at.map(|end_at| end_at <= run_at).unwrap_or(false) { return None; } - // We do checked_add here only to avoid a mere possibility of internal panic. - let run_at = now.checked_add(data.period)?; Some(Scheduled { data, run_at }) } }