2020-08-25 02:30:00 -07:00
|
|
|
defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
|
|
|
|
use Ecto.Migration
|
|
|
|
|
|
|
|
import Ecto.Query, only: [from: 2]
|
|
|
|
|
|
|
|
def change do
|
2020-09-13 00:04:50 -07:00
|
|
|
Pleroma.Config.Oban.warn()
|
|
|
|
|
2020-08-25 02:30:00 -07:00
|
|
|
Supervisor.start_link([{Oban, Pleroma.Config.get(Oban)}],
|
|
|
|
strategy: :one_for_one,
|
|
|
|
name: Pleroma.Supervisor
|
|
|
|
)
|
|
|
|
|
|
|
|
from(e in "activity_expirations",
|
|
|
|
select: %{id: e.id, activity_id: e.activity_id, scheduled_at: e.scheduled_at}
|
|
|
|
)
|
2020-09-03 08:08:19 -07:00
|
|
|
|> Pleroma.Repo.stream()
|
2020-09-04 02:05:17 -07:00
|
|
|
|> Stream.each(fn expiration ->
|
2020-09-03 08:08:19 -07:00
|
|
|
with {:ok, expires_at} <- DateTime.from_naive(expiration.scheduled_at, "Etc/UTC") do
|
|
|
|
Pleroma.Workers.PurgeExpiredActivity.enqueue(%{
|
|
|
|
activity_id: FlakeId.to_string(expiration.activity_id),
|
2020-09-08 05:11:18 -07:00
|
|
|
expires_at: expires_at
|
2020-09-03 08:08:19 -07:00
|
|
|
})
|
|
|
|
end
|
2020-08-25 02:30:00 -07:00
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
end
|