Upgrade oban to 2.0

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-08-12 14:34:19 +02:00
parent f4e06455a3
commit 9a0068dfea
12 changed files with 67 additions and 70 deletions

View File

@@ -14,7 +14,9 @@ defmodule Mobilizon.Service.Workers.Notification do
use Mobilizon.Service.Workers.Helper, queue: "mailers"
@impl Oban.Worker
def perform(%{"op" => "before_event_notification", "participant_id" => participant_id}, _job) do
def perform(%Job{
args: %{"op" => "before_event_notification", "participant_id" => participant_id}
}) do
with %Participant{actor: %Actor{user_id: user_id}, event: %Event{status: :confirmed}} =
participant <- Events.get_participant(participant_id),
%User{email: email, locale: locale, settings: %Setting{notification_before_event: true}} <-
@@ -27,7 +29,9 @@ defmodule Mobilizon.Service.Workers.Notification do
end
end
def perform(%{"op" => "on_day_notification", "user_id" => user_id}, _job) do
def perform(%Job{
args: %{"op" => "on_day_notification", "user_id" => user_id}
}) do
with %User{locale: locale, settings: %Setting{timezone: timezone, notification_on_day: true}} =
user <- Users.get_user_with_settings!(user_id),
{start, tomorrow} <- calculate_start_end(1, timezone),
@@ -52,7 +56,9 @@ defmodule Mobilizon.Service.Workers.Notification do
end
end
def perform(%{"op" => "weekly_notification", "user_id" => user_id}, _job) do
def perform(%Job{
args: %{"op" => "weekly_notification", "user_id" => user_id}
}) do
with %User{
locale: locale,
settings: %Setting{timezone: timezone, notification_each_week: true}
@@ -80,14 +86,13 @@ defmodule Mobilizon.Service.Workers.Notification do
end
end
def perform(
%{
def perform(%Job{
args: %{
"op" => "pending_participation_notification",
"user_id" => user_id,
"event_id" => event_id
},
_job
) do
}
}) do
with %User{} = user <- Users.get_user(user_id),
{:ok, %Event{} = event} <- Events.get_event(event_id),
%Page{total: total} when total > 0 <-