2020-01-22 23:55:07 +00:00
|
|
|
defmodule Mobilizon.Service.Workers.Background do
|
2019-12-03 10:29:51 +00:00
|
|
|
@moduledoc """
|
2020-02-18 07:57:00 +00:00
|
|
|
Worker to perform various actions in the background
|
2019-12-03 10:29:51 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
alias Mobilizon.Actors
|
|
|
|
alias Mobilizon.Actors.Actor
|
|
|
|
|
2020-01-22 23:55:07 +00:00
|
|
|
use Mobilizon.Service.Workers.Helper, queue: "background"
|
2019-12-03 10:29:51 +00:00
|
|
|
|
|
|
|
@impl Oban.Worker
|
2020-08-12 12:34:19 +00:00
|
|
|
def perform(%Job{args: %{"op" => "delete_actor", "actor_id" => actor_id} = args}) do
|
2020-06-11 17:13:21 +00:00
|
|
|
with reserve_username when is_boolean(reserve_username) <-
|
|
|
|
Map.get(args, "reserve_username", true),
|
|
|
|
%Actor{} = actor <- Actors.get_actor(actor_id) do
|
|
|
|
Actors.perform(:delete_actor, actor, reserve_username: reserve_username)
|
2019-12-03 10:29:51 +00:00
|
|
|
end
|
|
|
|
end
|
2020-02-14 16:56:36 +00:00
|
|
|
|
2020-08-12 12:34:19 +00:00
|
|
|
def perform(%Job{args: %{"op" => "actor_key_rotation", "actor_id" => actor_id}}) do
|
2020-02-14 16:56:36 +00:00
|
|
|
with %Actor{} = actor <- Actors.get_actor(actor_id) do
|
|
|
|
Actors.actor_key_rotation(actor)
|
|
|
|
end
|
|
|
|
end
|
2019-12-03 10:29:51 +00:00
|
|
|
end
|