I have Worker to create or update an struct scheduled in 30 seconds
use Oban.Worker,
queue: :default,
unique: [period: :infinity, states: [:available, :scheduled]]
and create a job
def create_later(args) do
args |> MyWorker.new(scheduled_in: 30) |> Oban.insert()
end
And I test it
# create struct
create_later(args)
Oban.drain_queue(queue: :default, with_scheduled: true)
# get created struct
get(id)
This is just pseudo code.
I expected, drain_queue will execute scheduled jobs (and there are scheduled jobs I confirmed with all_enqueued function)
But call drain_queue cause ex_unit timed out. it looks like it stuck in infinite loop or something…
Anyone has a any clue for this?? What am I doing wrong?
Just curious are you using the latest version of Oban?
A month ago I witnessed something similar, when running drain_jobs
with Oban.Pro
workflows, apparently it was a bug that was fixed in a week after reporting it
There is most likely an infinite loop or something waiting indefinitely within your worker.
Try changing your worker’s perform/1
function to a no-op to see if it processes immediately, as you’d expect. You can also use the with_safety: false
option to raise processing exceptions or crashes up to the test process to help debug.
Oban version
oban 2.14.2
oban_pro 0.13.2
oban_web 2.9.6
Ok I will check.
But weird thing is that, it only fails on my end. Other team member has no failing test.
original code looks like this, without draing-queue
create_later(args)
# get created struct
get(id)
But the get
function return nil
only on my end, so I added drain_queue
.
If you’re using Pro you should definitely use drain_jobs
from Oban.Pro.Testing. It has better defaults, more options, and is designed to work with chunks/batches/workflows in tests.