1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Workers.PurgeExpiredToken do
7 Worker which purges expired OAuth tokens
10 use Oban.Worker, queue: :token_expiration, max_attempts: 1
12 @spec enqueue(%{token_id: integer(), valid_until: DateTime.t(), mod: module()}) ::
13 {:ok, Oban.Job.t()} | {:error, Ecto.Changeset.t()}
15 {scheduled_at, args} = Map.pop(args, :valid_until)
18 |> __MODULE__.new(scheduled_at: scheduled_at)
23 def perform(%Oban.Job{args: %{"token_id" => id, "mod" => module}}) do
25 |> String.to_existing_atom()
26 |> Pleroma.Repo.get(id)
27 |> Pleroma.Repo.delete()
31 def timeout(_job), do: :timer.seconds(5)