mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-27 00:09:35 +00:00
Isolate OAuth.Token.CleanWorker
This commit is contained in:
parent
51bdf0cab6
commit
15ef521009
|
@ -59,6 +59,7 @@ defmodule Pleroma.Application do
|
||||||
restart: :temporary
|
restart: :temporary
|
||||||
}
|
}
|
||||||
] ++
|
] ++
|
||||||
|
oauth_cleanup_child(oauth_cleanup_enabled?()) ++
|
||||||
streamer_child(@env) ++
|
streamer_child(@env) ++
|
||||||
chat_child(@env, chat_enabled?()) ++
|
chat_child(@env, chat_enabled?()) ++
|
||||||
[
|
[
|
||||||
|
@ -134,12 +135,20 @@ defmodule Pleroma.Application do
|
||||||
|
|
||||||
defp chat_enabled?, do: Pleroma.Config.get([:chat, :enabled])
|
defp chat_enabled?, do: Pleroma.Config.get([:chat, :enabled])
|
||||||
|
|
||||||
|
defp oauth_cleanup_enabled?,
|
||||||
|
do: Pleroma.Config.get([:oauth2, :clean_expired_tokens], false)
|
||||||
|
|
||||||
defp streamer_child(:test), do: []
|
defp streamer_child(:test), do: []
|
||||||
|
|
||||||
defp streamer_child(_) do
|
defp streamer_child(_) do
|
||||||
[Pleroma.Web.Streamer]
|
[Pleroma.Web.Streamer]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp oauth_cleanup_child(true),
|
||||||
|
do: [Pleroma.Web.OAuth.Token.CleanWorker]
|
||||||
|
|
||||||
|
defp oauth_cleanup_child(_), do: []
|
||||||
|
|
||||||
defp chat_child(:test, _), do: []
|
defp chat_child(:test, _), do: []
|
||||||
|
|
||||||
defp chat_child(_env, true) do
|
defp chat_child(_env, true) do
|
||||||
|
|
|
@ -8,35 +8,28 @@ defmodule Pleroma.Web.OAuth.Token.CleanWorker do
|
||||||
"""
|
"""
|
||||||
use GenServer
|
use GenServer
|
||||||
|
|
||||||
# 10 seconds
|
@ten_seconds 10_000
|
||||||
@start_interval 10_000
|
@one_day 86_400_000
|
||||||
|
|
||||||
@interval Pleroma.Config.get(
|
@interval Pleroma.Config.get(
|
||||||
# 24 hours
|
|
||||||
[:oauth2, :clean_expired_tokens_interval],
|
[:oauth2, :clean_expired_tokens_interval],
|
||||||
86_400_000
|
@one_day
|
||||||
)
|
)
|
||||||
@queue :background
|
|
||||||
|
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
|
|
||||||
def start_link(_), do: GenServer.start_link(__MODULE__, nil)
|
def start_link(_), do: GenServer.start_link(__MODULE__, %{})
|
||||||
|
|
||||||
def init(_) do
|
def init(_) do
|
||||||
if Pleroma.Config.get([:oauth2, :clean_expired_tokens], false) do
|
Process.send_after(self(), :perform, @ten_seconds)
|
||||||
Process.send_after(self(), :perform, @start_interval)
|
{:ok, nil}
|
||||||
{:ok, nil}
|
|
||||||
else
|
|
||||||
:ignore
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def handle_info(:perform, state) do
|
def handle_info(:perform, state) do
|
||||||
|
Token.delete_expired_tokens()
|
||||||
|
|
||||||
Process.send_after(self(), :perform, @interval)
|
Process.send_after(self(), :perform, @interval)
|
||||||
PleromaJobQueue.enqueue(@queue, __MODULE__, [:clean])
|
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Job Worker Callbacks
|
|
||||||
def perform(:clean), do: Token.delete_expired_tokens()
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue