585d1a600ff5e85d604087f938fe570839e44f21
[akkoma] / priv / repo / migrations / 20200825061316_move_activity_expirations_to_oban.exs
1 defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
2 use Ecto.Migration
3
4 import Ecto.Query, only: [from: 2]
5
6 def change do
7 Supervisor.start_link([{Oban, Pleroma.Config.get(Oban)}],
8 strategy: :one_for_one,
9 name: Pleroma.Supervisor
10 )
11
12 from(e in "activity_expirations",
13 select: %{id: e.id, activity_id: e.activity_id, scheduled_at: e.scheduled_at}
14 )
15 |> Pleroma.RepoStreamer.chunk_stream(500)
16 |> Stream.each(fn expirations ->
17 Enum.each(expirations, fn expiration ->
18 with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
19 Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
20 activity_id: FlakeId.to_string(expiration.activity_id),
21 expires_at: expires_at,
22 validate: false
23 })
24 end
25 end)
26 end)
27 |> Stream.run()
28 end
29 end