logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

oban_helpers.ex (1029B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Tests.ObanHelpers do
  5. @moduledoc """
  6. Oban test helpers.
  7. """
  8. require Ecto.Query
  9. alias Pleroma.Repo
  10. def wipe_all do
  11. Repo.delete_all(Oban.Job)
  12. end
  13. def perform_all do
  14. Oban.Job
  15. |> Ecto.Query.where(state: "available")
  16. |> Repo.all()
  17. |> perform()
  18. end
  19. def perform(%Oban.Job{} = job) do
  20. res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job])
  21. Repo.delete(job)
  22. res
  23. end
  24. def perform(jobs) when is_list(jobs) do
  25. for job <- jobs, do: perform(job)
  26. end
  27. def member?(%{} = job_args, jobs) when is_list(jobs) do
  28. Enum.any?(jobs, fn job ->
  29. member?(job_args, job.args)
  30. end)
  31. end
  32. def member?(%{} = test_attrs, %{} = attrs) do
  33. Enum.all?(
  34. test_attrs,
  35. fn {k, _v} -> member?(test_attrs[k], attrs[k]) end
  36. )
  37. end
  38. def member?(x, y), do: x == y
  39. end