logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

20200907092050_move_tokens_expiration_into_oban.exs (1346B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.MoveTokensExpirationIntoOban do
  5. use Ecto.Migration
  6. import Ecto.Query, only: [from: 2]
  7. def change do
  8. Pleroma.Config.Oban.warn()
  9. Application.ensure_all_started(:oban)
  10. Supervisor.start_link([{Oban, Pleroma.Config.get(Oban)}],
  11. strategy: :one_for_one,
  12. name: Pleroma.Supervisor
  13. )
  14. if Pleroma.Config.get([:oauth2, :clean_expired_tokens]) do
  15. from(t in Pleroma.Web.OAuth.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
  16. |> Pleroma.Repo.stream()
  17. |> Stream.each(fn token ->
  18. Pleroma.Workers.PurgeExpiredToken.enqueue(%{
  19. token_id: token.id,
  20. valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
  21. mod: Pleroma.Web.OAuth.Token
  22. })
  23. end)
  24. |> Stream.run()
  25. end
  26. from(t in Pleroma.MFA.Token, where: t.valid_until > ^NaiveDateTime.utc_now())
  27. |> Pleroma.Repo.stream()
  28. |> Stream.each(fn token ->
  29. Pleroma.Workers.PurgeExpiredToken.enqueue(%{
  30. token_id: token.id,
  31. valid_until: DateTime.from_naive!(token.valid_until, "Etc/UTC"),
  32. mod: Pleroma.MFA.Token
  33. })
  34. end)
  35. |> Stream.run()
  36. end
  37. end