debianize-mobilizon/lib/service/workers/background.ex
Thomas Citharel 75e254d8b4
Actor suspension refactoring
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2021-09-26 17:52:23 +02:00

34 lines
1.1 KiB
Elixir

defmodule Mobilizon.Service.Workers.Background do
@moduledoc """
Worker to perform various actions in the background
"""
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.ActivityPub.Refresher
alias Mobilizon.Service.ActorSuspension
use Mobilizon.Service.Workers.Helper, queue: "background"
@impl Oban.Worker
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
ActorSuspension.suspend_actor(actor, reserve_username: reserve_username)
end
end
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
end
def perform(%Job{args: %{"op" => "refresh_profile", "actor_id" => actor_id}}) do
with %Actor{} = actor <- Actors.get_actor(actor_id) do
Refresher.refresh_profile(actor)
end
end
end