2019-05-22 17:44:50 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2019-09-18 23:20:54 +02:00
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
2019-05-22 17:44:50 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.OAuth.Token.CleanWorker do
|
|
|
|
@moduledoc """
|
|
|
|
The module represents functions to clean an expired oauth tokens.
|
|
|
|
"""
|
2019-08-14 17:55:17 +02:00
|
|
|
use GenServer
|
2019-05-22 17:44:50 +02:00
|
|
|
|
2019-08-14 17:57:50 +02:00
|
|
|
@ten_seconds 10_000
|
|
|
|
@one_day 86_400_000
|
2019-05-22 17:44:50 +02:00
|
|
|
|
|
|
|
alias Pleroma.Web.OAuth.Token
|
2019-08-13 19:20:26 +02:00
|
|
|
alias Pleroma.Workers.BackgroundWorker
|
|
|
|
|
2019-08-14 17:57:50 +02:00
|
|
|
def start_link(_), do: GenServer.start_link(__MODULE__, %{})
|
2019-05-22 17:44:50 +02:00
|
|
|
|
|
|
|
def init(_) do
|
2019-08-14 17:57:50 +02:00
|
|
|
Process.send_after(self(), :perform, @ten_seconds)
|
|
|
|
{:ok, nil}
|
2019-05-22 17:44:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def handle_info(:perform, state) do
|
2019-08-31 20:58:42 +02:00
|
|
|
BackgroundWorker.enqueue("clean_expired_tokens", %{})
|
2019-12-08 15:36:44 +01:00
|
|
|
interval = Pleroma.Config.get([:oauth2, :clean_expired_tokens_interval], @one_day)
|
2019-08-13 19:20:26 +02:00
|
|
|
|
2019-12-08 15:36:44 +01:00
|
|
|
Process.send_after(self(), :perform, interval)
|
2019-05-22 17:44:50 +02:00
|
|
|
{:noreply, state}
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform(:clean), do: Token.delete_expired_tokens()
|
|
|
|
end
|