Issue when running two jobs in seeds.exs

I have a function that inserts a job that I’m calling twice in seeds.exs:

function_a(args1)
function_a(args2)

When running mix run priv/repo/seeds.exs as above, whichever job is listed first gets stuck in “executing” and the other completes as expected. When running with a short sleep in between, both complete as expected:

function_a(args1)
:timer.sleep(10_000)
function_a(args1)

i’m using:
{:oban, “~> 2.19”},
{:oban_pro, “~> 1.6.0-rc.1”, repo: “oban”}

def function_a(args) do
    Repo.transact(fn ->
      with {:ok, result} <- function(attrs1),
           {:ok, result2} <- function2(attrs2),
           {:ok, job} <- JobName.new(map) |> Oban.insert() do
        {:ok, %{result: result, result2: result2, job: job}}
      end
    end)
end

It helps to show code pieces in function_a that are relevant to Oban.

Added!

Is the goal to run the jobs while seeding? It seems like the job is picked up while the seed script runs, then the script ends and the system shuts down before it can run.

Disable all queues, or pause that queue, while running the seeds script to prevent the job from starting then.

2 Likes