Merge branch 'scheduler-fixes' into 'master'

Scheduler fixes

See merge request framasoft/mobilizon!486
This commit is contained in:
Thomas Citharel 2020-06-24 12:03:57 +02:00
commit 5d164761fd
2 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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