2020-01-23 00:55:07 +01:00
|
|
|
defmodule Mobilizon.Service.Workers.Background do
|
2019-12-03 11:29:51 +01:00
|
|
|
@moduledoc """
|
2020-02-18 08:57:00 +01:00
|
|
|
Worker to perform various actions in the background
|
2019-12-03 11:29:51 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
alias Mobilizon.Actors
|
|
|
|
alias Mobilizon.Actors.Actor
|
2021-05-12 18:18:20 +02:00
|
|
|
alias Mobilizon.Federation.ActivityPub.Refresher
|
2021-09-10 11:36:05 +02:00
|
|
|
alias Mobilizon.Service.ActorSuspension
|
2019-12-03 11:29:51 +01:00
|
|
|
|
2020-01-23 00:55:07 +01:00
|
|
|
use Mobilizon.Service.Workers.Helper, queue: "background"
|
2019-12-03 11:29:51 +01:00
|
|
|
|
|
|
|
@impl Oban.Worker
|
2021-09-24 16:46:42 +02:00
|
|
|
@spec perform(Job.t()) ::
|
|
|
|
{:ok, Actor.t()}
|
|
|
|
| {:error,
|
|
|
|
:actor_not_found | :bad_option_value_for_reserve_username | Ecto.Changeset.t()}
|
2020-08-12 14:34:19 +02:00
|
|
|
def perform(%Job{args: %{"op" => "delete_actor", "actor_id" => actor_id} = args}) do
|
2021-09-24 16:46:42 +02:00
|
|
|
case Map.get(args, "reserve_username", true) do
|
|
|
|
reserve_username when is_boolean(reserve_username) ->
|
|
|
|
case Actors.get_actor(actor_id) do
|
|
|
|
%Actor{} = actor ->
|
2023-12-04 09:02:38 +01:00
|
|
|
ActorSuspension.suspend_actor(actor,
|
|
|
|
reserve_username: reserve_username,
|
|
|
|
suspension: Map.get(args, "suspension", false)
|
|
|
|
)
|
2021-09-24 16:46:42 +02:00
|
|
|
|
|
|
|
nil ->
|
|
|
|
{:error, :actor_not_found}
|
|
|
|
end
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
{:error, :bad_option_value_for_reserve_username}
|
2019-12-03 11:29:51 +01:00
|
|
|
end
|
|
|
|
end
|
2020-02-14 17:56:36 +01:00
|
|
|
|
2020-08-12 14:34:19 +02:00
|
|
|
def perform(%Job{args: %{"op" => "actor_key_rotation", "actor_id" => actor_id}}) do
|
2020-02-14 17:56:36 +01:00
|
|
|
with %Actor{} = actor <- Actors.get_actor(actor_id) do
|
|
|
|
Actors.actor_key_rotation(actor)
|
|
|
|
end
|
|
|
|
end
|
2021-05-12 18:18:20 +02:00
|
|
|
|
|
|
|
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
|
2019-12-03 11:29:51 +01:00
|
|
|
end
|