Resolve merge conflicts
[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
10 # 10 seconds
11 @start_interval 10_000
12 @interval Pleroma.Config.get(
13 # 24 hours
14 [:oauth2, :clean_expired_tokens_interval],
15 86_400_000
16 )
17 @queue :background
18
19 alias Pleroma.Web.OAuth.Token
20
21 def start_link, do: GenServer.start_link(__MODULE__, nil)
22
23 def init(_) do
24 if Pleroma.Config.get([:oauth2, :clean_expired_tokens], false) do
25 Process.send_after(self(), :perform, @start_interval)
26 {:ok, nil}
27 else
28 :ignore
29 end
30 end
31
32 @doc false
33 def handle_info(:perform, state) do
34 Process.send_after(self(), :perform, @interval)
35 PleromaJobQueue.enqueue(@queue, __MODULE__, [:clean])
36 {:noreply, state}
37 end
38
39 # Job Worker Callbacks
40 def perform(:clean), do: Token.delete_expired_tokens()
41 end