summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-11-12 12:34:48 +0000
committerrinpatch <rinpatch@sdf.org>2020-11-12 12:34:48 +0000
commit1172844ed18d94d84724dc6f11c6e9f72e0ba6ec (patch)
tree7d48a259e08856ab6db0eba255f20c0c19410463 /priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs
parenta0f5e8b27edbe2224d9c2c3997ad5b8ea484244b (diff)
parentb4c6b262d6dc12362f0014a864e8aed6c727c39c (diff)
Merge branch 'release/2.2.0' into 'stable'v2.2.0
Release/2.2.0 See merge request pleroma/secteam/pleroma!19
Diffstat (limited to 'priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs')
-rw-r--r--priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs28
1 files changed, 28 insertions, 0 deletions
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..a703af83f
--- /dev/null
+++ b/priv/repo/migrations/20200825061316_move_activity_expirations_to_oban.exs
@@ -0,0 +1,28 @@
+defmodule Pleroma.Repo.Migrations.MoveActivityExpirationsToOban do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ def change do
+ Pleroma.Config.Oban.warn()
+
+ 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.Repo.stream()
+ |> Stream.each(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
+ })
+ end
+ end)
+ |> Stream.run()
+ end
+end