From 378a1130028bddd457db85e7e3845c11ee2b3427 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 24 Jun 2020 11:31:32 +0200 Subject: [PATCH] Scheduler fixes Signed-off-by: Thomas Citharel --- CHANGELOG.md | 6 ++++++ lib/service/notifications/scheduler.ex | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c44f0b85c..baec80c89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fixed notification scheduler (!486)[https://framagit.org/framasoft/mobilizon/-/merge_requests/486] + ## [1.0.0-beta.3] - 2020-06-24 ### Special operations diff --git a/lib/service/notifications/scheduler.ex b/lib/service/notifications/scheduler.ex index 2bdf2928e..244746504 100644 --- a/lib/service/notifications/scheduler.ex +++ b/lib/service/notifications/scheduler.ex @@ -41,7 +41,7 @@ defmodule Mobilizon.Service.Notifications.Scheduler do send_date = cond do - begins_on < DateTime.utc_now() -> + DateTime.compare(begins_on, DateTime.utc_now()) == :lt -> nil hour > 8 -> @@ -60,7 +60,7 @@ defmodule Mobilizon.Service.Notifications.Scheduler do "Participation notification should be sent at #{inspect(send_date)} (user timezone)" ) - if DateTime.utc_now() > send_date do + if is_nil(send_date) or DateTime.compare(DateTime.utc_now(), send_date) == :gt do {:ok, "Too late to send same day notifications"} else Notification.enqueue(:on_day_notification, %{user_id: user_id}, scheduled_at: send_date) @@ -91,7 +91,7 @@ defmodule Mobilizon.Service.Notifications.Scheduler do ) notification_date = - unless begins_on < DateTime.utc_now() do + if Date.compare(begins_on, DateTime.utc_now()) == :gt do notification_day = calculate_first_day_of_week(DateTime.to_date(begins_on), locale) {:ok, %NaiveDateTime{} = notification_date} = @@ -101,7 +101,7 @@ defmodule Mobilizon.Service.Notifications.Scheduler do {:ok, %DateTime{} = notification_date} = DateTime.from_naive(notification_date, timezone) - unless notification_date < DateTime.utc_now() do + if Date.compare(notification_date, DateTime.utc_now()) == :gt do notification_date else nil @@ -204,7 +204,7 @@ defmodule Mobilizon.Service.Notifications.Scheduler do {:ok, send_at} = NaiveDateTime.new(day, ~T[18:00:00]) {:ok, send_at} = DateTime.from_naive(send_at, timezone) - if send_at < DateTime.utc_now() do + if DateTime.compare(send_at, DateTime.utc_now()) == :lt do calculate_first_day_of_week(Date.add(day, 1), timezone) else send_at