{: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
]