From 5ad0cc4c863f7f8a1e6fdfa40eb884a5c94ebf67 Mon Sep 17 00:00:00 2001 From: Alexander Strizhakov Date: Tue, 25 Aug 2020 12:30:00 +0300 Subject: [PATCH] move old expirations into Oban --- ...1316_move_activity_expirations_to_oban.exs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs diff --git a/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs new file mode 100644 index 000000000..585d1a600 --- /dev/null +++ b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs @@ -0,0 +1,29 @@ +defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do + use Ecto.Migration + + import Ecto.Query, only: [from: 2] + + def change do + 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} + ) + |> Pleroma.RepoStreamer.chunk_stream(500) + |> Stream.each(fn expirations -> + Enum.each(expirations, fn expiration -> + 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), + expires_at: expires_at, + validate: false + }) + end + end) + end) + |> Stream.run() + end +end -- 2.45.2