mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-12-27 19:09:12 +00:00
39 lines
1,005 B
Elixir
39 lines
1,005 B
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.OAuth.Token.CleanWorker do
|
|
@moduledoc """
|
|
The module represents functions to clean an expired OAuth and MFA tokens.
|
|
"""
|
|
use GenServer
|
|
|
|
@ten_seconds 10_000
|
|
@one_day 86_400_000
|
|
|
|
alias Pleroma.MFA
|
|
alias Pleroma.Web.OAuth
|
|
alias Pleroma.Workers.BackgroundWorker
|
|
|
|
def start_link(_), do: GenServer.start_link(__MODULE__, %{})
|
|
|
|
def init(_) do
|
|
Process.send_after(self(), :perform, @ten_seconds)
|
|
{:ok, nil}
|
|
end
|
|
|
|
@doc false
|
|
def handle_info(:perform, state) do
|
|
BackgroundWorker.enqueue("clean_expired_tokens", %{})
|
|
interval = Pleroma.Config.get([:oauth2, :clean_expired_tokens_interval], @one_day)
|
|
|
|
Process.send_after(self(), :perform, interval)
|
|
{:noreply, state}
|
|
end
|
|
|
|
def perform(:clean) do
|
|
OAuth.Token.delete_expired_tokens()
|
|
MFA.Token.delete_expired_tokens()
|
|
end
|
|
end
|