Add fail cutoff for reminder updating
This commit is contained in:
parent
fa542bb24f
commit
799298ca34
@ -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!(
|
||||
|
Loading…
Reference in New Issue
Block a user