Oban.insert waits for the job to complete instead of returning immediately

{:oban, "~> 2.15"}

I’m experiencing a weird behaviour with Oban.insert. When I call it, it waits until the enqueued job finishes, and only then returns with %Oban.Job{state="completed"}. My understanding is that it should just enqueue the job, and return immediately.

The queue config:

config :my_app, Oban,
  repo: Quire.Repo,
  plugins: [{Oban.Plugins.Pruner, max_age: 300}, {Oban.Plugins.Reindexer, schedule: "@weekly"}],
  queues: [
    default: 10,
    image_resize: 10,
  ]

The worker:

defmodule MyApp.ImageResize do
  use Oban.Worker, queue: :image_resize

  @impl Oban.Worker
  def perform(%Oban.Job{args: %{"media_id" => media_id}}) do
    # logic to resize images, including retrieveing data from the db, writing data to db etc.
  end
end

Getting this into Oban:

%{media_id: "x"} |> MyApp.ImageResize.new() |> Oban.insert()

This last line waits until the entirety of the job completes before returning. I believe this isn’t right?


Moreover:

%{media_id: "x"} |> MyApp.ImageResize.new(schedule_in: 5) |> Oban.insert()

Still starts the job immediately, and waits for it to finish.


Edit:

> Application.get_env(:my_app, Oban)
[
  repo: MyApp.Repo,
  plugins: [
    {Oban.Plugins.Pruner, [max_age: 300]},
    {Oban.Plugins.Reindexer, [schedule: "@weekly"]}
  ],
  queues: [default: 10, image_resize: 10],
  testing: :inline
]

Hey @dmitriid can you show the output of Application.get_env(:my_app, Oban) ?

Ah, sorry, forgot to provide it

[
  repo: MyApp.Repo,
  plugins: [
    {Oban.Plugins.Pruner, [max_age: 300]},
    {Oban.Plugins.Reindexer, [schedule: "@weekly"]}
  ],
  queues: [default: 10, image_resize: 10],
  testing: :inline
]

That testing inline option is why this is happening. Are you setting that in config.exs and not test.exs?

2 Likes

Argh.

I did indeed have that as separate line in config.exs, and didnt’ notice it :slight_smile: And now it works as expected

1 Like