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
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
12 changed files with 67 additions and 70 deletions

View File

@ -235,7 +235,7 @@ config :mobilizon, :anonymous,
config :mobilizon, Oban,
repo: Mobilizon.Storage.Repo,
prune: {:maxlen, 10_000},
log: false,
queues: [default: 10, search: 5, mailers: 10, background: 5]
config :mobilizon, :rich_media,

View File

@ -51,7 +51,7 @@ config :tesla, Mobilizon.Service.HTTP.BaseClient, adapter: Mobilizon.Service.HTT
config :mobilizon, Mobilizon.Service.Geospatial, service: Mobilizon.Service.Geospatial.Mock
config :mobilizon, Oban, queues: false, prune: :disabled, crontab: false
config :mobilizon, Oban, queues: false, crontab: false, plugins: false
config :mobilizon, Mobilizon.Web.Auth.Guardian, secret_key: "some secret"

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

View File

@ -116,7 +116,7 @@ defmodule Mobilizon.Mixfile do
{:ex_cldr_dates_times, "~> 2.2"},
{:ex_optimizer, "~> 0.1"},
{:progress_bar, "~> 2.0"},
{:oban, "~> 1.2.0"},
{:oban, "~> 2.0.0"},
{:floki, "~> 0.27.0"},
{:ip_reserved, "~> 0.1.0"},
{:fast_sanitize, "~> 0.1"},

View File

@ -100,7 +100,7 @@
"nimble_pool": {:hex, :nimble_pool, "0.1.0", "ffa9d5be27eee2b00b0c634eb649aa27f97b39186fec3c493716c2a33e784ec6", [:mix], [], "hexpm", "343a1eaa620ddcf3430a83f39f2af499fe2370390d4f785cd475b4df5acaf3f9"},
"oauth2": {:hex, :oauth2, "2.0.0", "338382079fe16c514420fa218b0903f8ad2d4bfc0ad0c9f988867dfa246731b0", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "881b8364ac7385f9fddc7949379cbe3f7081da37233a1aa7aab844670a91e7e7"},
"oauther": {:hex, :oauther, "1.1.1", "7d8b16167bb587ecbcddd3f8792beb9ec3e7b65c1f8ebd86b8dd25318d535752", [:mix], [], "hexpm", "9374f4302045321874cccdc57eb975893643bd69c3b22bf1312dab5f06e5788e"},
"oban": {:hex, :oban, "1.2.0", "7cca94d341be43d220571e28f69131c4afc21095b25257397f50973d3fc59b07", [:mix], [{:ecto_sql, "~> 3.1", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ba5f8b3f7d76967b3e23cf8014f6a13e4ccb33431e4808f036709a7f822362ee"},
"oban": {:hex, :oban, "2.0.0", "e6ce70d94dd46815ec0882a1ffb7356df9a9d5b8a40a64ce5c2536617a447379", [:mix], [{:ecto_sql, ">= 3.4.3", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cf574813bd048b98a698aa587c21367d2e06842d4e1b1993dcd6a696e9e633bd"},
"ordinal": {:hex, :ordinal, "0.1.0", "2f7a1a64ff4be44b8a674718bb00d1584188fe92fa2fa48b95b1e72096d74a34", [:mix], [], "hexpm", "9f3d0a50c285ac99faa9626376e11afa6fc83d42e95166768b37d176cff485a3"},
"paddle": {:hex, :paddle, "0.1.4", "3697996d79e3d771d6f7560a23e4bad1ed7b7f7fd3e784f97bc39565963b2b13", [:mix], [], "hexpm", "fc719a9e7c86f319b9f4bf413d6f0f326b0c4930d5bc6630d074598ed38e2143"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},

View File

@ -861,7 +861,7 @@ defmodule Mobilizon.Federation.ActivityPub.TransmogrifierTest do
end)
{:ok, _activity, _actor} = Transmogrifier.handle_incoming(data)
assert %{success: 1, failure: 0} == Oban.drain_queue(:background)
assert %{success: 1, failure: 0} == Oban.drain_queue(queue: :background)
assert {:error, :actor_not_found} = Actors.get_actor_by_url(url)
assert {:error, :event_not_found} = Events.get_event(event1.id)

View File

@ -511,7 +511,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
args: %{"actor_id" => person_id, "op" => "delete_actor", "reserve_username" => true}
)
assert %{success: 1, failure: 0} == Oban.drain_queue(:background)
assert %{success: 1, failure: 0} == Oban.drain_queue(queue: :background)
query = """
{
@ -708,7 +708,7 @@ defmodule Mobilizon.GraphQL.Resolvers.PersonTest do
assert is_nil(res["errors"])
assert res["data"]["suspendProfile"]["id"] == to_string(remote_profile_id)
assert %{success: 1, failure: 0} == Oban.drain_queue(:background)
assert %{success: 1, failure: 0} == Oban.drain_queue(queue: :background)
res =
conn

View File

@ -1381,7 +1381,7 @@ defmodule Mobilizon.GraphQL.Resolvers.UserTest do
assert Users.get_user(user.id).disabled == true
assert %{success: 2, failure: 0} == Oban.drain_queue(:background)
assert %{success: 2, failure: 0} == Oban.drain_queue(queue: :background)
assert_raise Ecto.NoResultsError, fn ->
Events.get_event!(event_id)

View File

@ -370,7 +370,7 @@ defmodule Mobilizon.ActorsTest do
args: %{"actor_id" => actor.id, "op" => "delete_actor", "reserve_username" => true}
)
assert %{success: 1, failure: 0} == Oban.drain_queue(:background)
assert %{success: 1, failure: 0} == Oban.drain_queue(queue: :background)
assert %Actor{
name: nil,

View File

@ -32,10 +32,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
%Participant{id: participant_id} =
participant = insert(:participant, role: :participant, actor: actor)
Notification.perform(
%{"op" => "before_event_notification", "participant_id" => participant_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "before_event_notification", "participant_id" => participant_id}
})
assert_delivered_email(
NotificationMailer.before_event_notification(
@ -59,10 +58,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
assert {:ok, %Participant{}} = Events.delete_participant(participant)
Notification.perform(
%{"op" => "before_event_notification", "participant_id" => participant_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "before_event_notification", "participant_id" => participant_id}
})
refute_delivered_email(
NotificationMailer.before_event_notification(
@ -78,10 +76,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
%Participant{id: participant_id} =
participant = insert(:participant, role: :participant, event: event)
Notification.perform(
%{"op" => "before_event_notification", "participant_id" => participant_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "before_event_notification", "participant_id" => participant_id}
})
refute_delivered_email(
NotificationMailer.before_event_notification(
@ -104,10 +101,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
%Participant{} = participant = insert(:participant, role: :participant, actor: actor)
Notification.perform(
%{"op" => "on_day_notification", "user_id" => user_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "on_day_notification", "user_id" => user_id}
})
assert_delivered_email(
NotificationMailer.on_day_notification(
@ -137,10 +133,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
assert {:ok, %Participant{}} = Events.delete_participant(participant)
Notification.perform(
%{"op" => "on_day_notification", "user_id" => user_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "on_day_notification", "user_id" => user_id}
})
refute_delivered_email(
NotificationMailer.on_day_notification(
@ -164,10 +159,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
%Participant{} =
participant = insert(:participant, role: :participant, event: event, actor: actor)
Notification.perform(
%{"op" => "on_day_notification", "user_id" => user_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "on_day_notification", "user_id" => user_id}
})
refute_delivered_email(
NotificationMailer.on_day_notification(
@ -193,10 +187,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
acc ++ [participant]
end)
Notification.perform(
%{"op" => "on_day_notification", "user_id" => user_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "on_day_notification", "user_id" => user_id}
})
refute_delivered_email(
NotificationMailer.on_day_notification(
@ -220,10 +213,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
%Participant{} = participant = insert(:participant, role: :participant, actor: actor)
Notification.perform(
%{"op" => "weekly_notification", "user_id" => user_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "weekly_notification", "user_id" => user_id}
})
assert_delivered_email(
NotificationMailer.weekly_notification(
@ -253,10 +245,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
assert {:ok, %Participant{}} = Events.delete_participant(participant)
Notification.perform(
%{"op" => "weekly_notification", "user_id" => user_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "weekly_notification", "user_id" => user_id}
})
refute_delivered_email(
NotificationMailer.weekly_notification(
@ -280,10 +271,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
%Participant{} =
participant = insert(:participant, role: :participant, event: event, actor: actor)
Notification.perform(
%{"op" => "weekly_notification", "user_id" => user_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "weekly_notification", "user_id" => user_id}
})
refute_delivered_email(
NotificationMailer.weekly_notification(
@ -309,10 +299,9 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
acc ++ [participant]
end)
Notification.perform(
%{"op" => "weekly_notification", "user_id" => user_id},
nil
)
Notification.perform(%Oban.Job{
args: %{"op" => "weekly_notification", "user_id" => user_id}
})
refute_delivered_email(
NotificationMailer.weekly_notification(
@ -333,14 +322,13 @@ defmodule Mobilizon.Service.Workers.NotificationTest do
%Participant{} = insert(:participant, event: event, role: :not_approved)
%Participant{} = insert(:participant, event: event, role: :not_approved)
Notification.perform(
%{
Notification.perform(%Oban.Job{
args: %{
"op" => "pending_participation_notification",
"user_id" => user_id,
"event_id" => event_id
},
nil
)
}
})
assert_delivered_email(
NotificationMailer.pending_participation_notification(