dmitriid

dmitriid

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
]

Marked As Solved

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

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

Also Liked

dmitriid

dmitriid

Argh.

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

Where Next?

Popular in Questions Top

beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement