2022-02-26 06:11:42 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-01 11:11:47 +00:00
|
|
|
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
|
2022-02-26 06:11:42 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-08-25 09:30:00 +00:00
|
|
|
defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
|
|
|
|
use Ecto.Migration
|
|
|
|
|
|
|
|
import Ecto.Query, only: [from: 2]
|
|
|
|
|
|
|
|
def change do
|
2020-09-13 07:04:50 +00:00
|
|
|
Pleroma.Config.Oban.warn()
|
|
|
|
|
2021-01-17 06:58:41 +00:00
|
|
|
Application.ensure_all_started(:oban)
|
|
|
|
|
2020-08-25 09:30:00 +00: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 15:08:19 +00:00
|
|
|
|> Pleroma.Repo.stream()
|
2020-09-04 09:05:17 +00:00
|
|
|
|> Stream.each(fn expiration ->
|
2020-09-03 15:08:19 +00: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 12:11:18 +00:00
|
|
|
expires_at: expires_at
|
2020-09-03 15:08:19 +00:00
|
|
|
})
|
|
|
|
end
|
2020-08-25 09:30:00 +00:00
|
|
|
end)
|
|
|
|
|> Stream.run()
|
|
|
|
end
|
|
|
|
end
|