From 799298ca340ade6fe559f75351448da508559c5c Mon Sep 17 00:00:00 2001 From: jude Date: Tue, 20 Jun 2023 15:41:28 +0100 Subject: [PATCH] Add fail cutoff for reminder updating --- postman/src/sender.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/postman/src/sender.rs b/postman/src/sender.rs index eaffab9..66a01f9 100644 --- a/postman/src/sender.rs +++ b/postman/src/sender.rs @@ -361,8 +361,9 @@ WHERE let now = Utc::now(); let mut updated_reminder_time = self.utc_time.with_timezone(&self.timezone.parse().unwrap_or(Tz::UTC)); + let mut fail_count = 0; - while updated_reminder_time < now { + while updated_reminder_time < now && fail_count < 4 { if let Some(interval) = self.interval_months { if interval != 0 { updated_reminder_time = updated_reminder_time @@ -372,6 +373,7 @@ WHERE "{}: Could not add {} months to a reminder", interval, self.id ); + fail_count += 1; updated_reminder_time }); @@ -380,13 +382,14 @@ WHERE if let Some(interval) = self.interval_days { if interval != 0 { - if let Some(new_time) = - updated_reminder_time.checked_add_days(Days::new(interval as u64)) - { - updated_reminder_time = new_time - } else { - warn!("{}: Could not add {} days to a reminder", self.id, interval); - } + updated_reminder_time = updated_reminder_time + .checked_add_days(Days::new(interval as u64)) + .unwrap_or_else(|| { + warn!("{}: Could not add {} days to a reminder", self.id, interval); + fail_count += 1; + + updated_reminder_time + }) } } @@ -395,7 +398,11 @@ WHERE } } - if self.expires.map_or(false, |expires| updated_reminder_time > expires) { + if fail_count >= 4 { + error!("Reminder {} failed to update 4 times and so is being deleted", self.id); + + self.force_delete(pool).await; + } else if self.expires.map_or(false, |expires| updated_reminder_time > expires) { self.force_delete(pool).await; } else { sqlx::query!(