logo

pleroma

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

20200825061316_move_activity_expirations_to_oban.exs (1006B)


  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.MoveActivityExpirationsToOban 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. from(e in "activity_expirations",
  15. select: %{id: e.id, activity_id: e.activity_id, scheduled_at: e.scheduled_at}
  16. )
  17. |> Pleroma.Repo.stream()
  18. |> Stream.each(fn expiration ->
  19. with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
  20. Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
  21. activity_id: FlakeId.to_string(expiration.activity_id),
  22. expires_at: expires_at
  23. })
  24. end
  25. end)
  26. |> Stream.run()
  27. end
  28. end