Merge branch 'feature/optimize_rich_media_parser' into 'develop'
[akkoma] / lib / pleroma / web / oauth / token / clean_worker.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.OAuth.Token.CleanWorker do
6 @moduledoc """
7 The module represents functions to clean an expired oauth tokens.
8 """
9 use GenServer
10
11 @ten_seconds 10_000
12 @one_day 86_400_000
13
14 @interval Pleroma.Config.get(
15 [:oauth2, :clean_expired_tokens_interval],
16 @one_day
17 )
18
19 alias Pleroma.Web.OAuth.Token
20 alias Pleroma.Workers.BackgroundWorker
21
22 def start_link(_), do: GenServer.start_link(__MODULE__, %{})
23
24 def init(_) do
25 Process.send_after(self(), :perform, @ten_seconds)
26 {:ok, nil}
27 end
28
29 @doc false
30 def handle_info(:perform, state) do
31 BackgroundWorker.enqueue("clean_expired_tokens", %{})
32
33 Process.send_after(self(), :perform, @interval)
34 {:noreply, state}
35 end
36
37 def perform(:clean), do: Token.delete_expired_tokens()
38 end