summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20240729163838_publisher_job_change.exs
blob: 08d73b5ad178c903e12308b1d0e6a09e779c9831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
defmodule Pleroma.Repo.Migrations.PublisherJobChange do
  use Ecto.Migration

  alias Pleroma.Activity
  import Ecto.Query

  def up do
    query =
      from(j in Oban.Job,
        where: j.worker == "Pleroma.Workers.PublisherWorker",
        where: j.state in ["available", "retryable"]
      )

    jobs =
      Oban |> Oban.config() |> Oban.Repo.all(query)

    Enum.each(jobs, fn job ->
      args = job.args
      activity = Activity.get_by_ap_id(args["id"])

      updated_args = Map.put(args, "activity_id", activity.id)

      Pleroma.Workers.PublisherWorker.new(updated_args)
      |> Oban.insert()
    end)
  end
end