2020-11-26 14:48:10 +01:00
|
|
|
defmodule Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker do
|
|
|
|
@moduledoc """
|
|
|
|
Worker to clean unattached media
|
|
|
|
"""
|
|
|
|
|
|
|
|
use Oban.Worker, queue: "background"
|
|
|
|
alias Mobilizon.Service.CleanUnconfirmedUsers
|
|
|
|
|
|
|
|
@impl Oban.Worker
|
|
|
|
def perform(%Job{}) do
|
|
|
|
if Mobilizon.Config.get!([:instance, :remove_unconfirmed_users]) and should_perform?() do
|
|
|
|
CleanUnconfirmedUsers.clean()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@spec should_perform? :: boolean()
|
|
|
|
defp should_perform? do
|
2021-12-15 09:47:12 +01:00
|
|
|
case Cachex.get(:key_value, "unconfirmed_users_cleanup") do
|
|
|
|
{:ok, %DateTime{} = unconfirmed_users_cleanup} ->
|
2021-06-07 10:24:57 +02:00
|
|
|
default_grace_period =
|
|
|
|
Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
|
|
|
|
|
2020-11-26 14:48:10 +01:00
|
|
|
DateTime.compare(
|
2021-12-15 09:47:12 +01:00
|
|
|
unconfirmed_users_cleanup,
|
2021-06-07 10:24:57 +02:00
|
|
|
DateTime.add(DateTime.utc_now(), default_grace_period * -3600)
|
2020-11-26 14:48:10 +01:00
|
|
|
) == :lt
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|