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

@@ -9,7 +9,7 @@ defmodule Mobilizon.Service.Workers.Background do
use Mobilizon.Service.Workers.Helper, queue: "background"
@impl Oban.Worker
def perform(%{"op" => "delete_actor", "actor_id" => actor_id} = args, _job) do
def perform(%Job{args: %{"op" => "delete_actor", "actor_id" => actor_id} = args}) do
with reserve_username when is_boolean(reserve_username) <-
Map.get(args, "reserve_username", true),
%Actor{} = actor <- Actors.get_actor(actor_id) do
@@ -17,7 +17,7 @@ defmodule Mobilizon.Service.Workers.Background do
end
end
def perform(%{"op" => "actor_key_rotation", "actor_id" => actor_id}, _job) do
def perform(%Job{args: %{"op" => "actor_key_rotation", "actor_id" => actor_id}}) do
with %Actor{} = actor <- Actors.get_actor(actor_id) do
Actors.actor_key_rotation(actor)
end

View File

@@ -13,13 +13,17 @@ defmodule Mobilizon.Service.Workers.BuildSearch do
use Mobilizon.Service.Workers.Helper, queue: "search"
@impl Oban.Worker
def perform(%{"op" => "insert_search_event", "event_id" => event_id}, _job) do
def perform(%Job{
args: %{"op" => "insert_search_event", "event_id" => event_id}
}) do
with {:ok, %Event{} = event} <- Events.get_event_with_preload(event_id) do
insert_search_event(event)
end
end
def perform(%{"op" => "update_search_event", "event_id" => event_id}, _job) do
def perform(%Job{
args: %{"op" => "update_search_event", "event_id" => event_id}
}) do
with {:ok, %Event{} = event} <- Events.get_event_with_preload(event_id) do
insert_search_event(event)
end

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