andreyuhai
I am trying to insert another Oban job after one finishes by listening to [:oban, :job, :stop].
I’d like to assert that the next job was queued after one succeeded, so in my test I do something like this ![]()
test "schedules job after another" do
# ...
{:ok, result} =
perform_job(Workers.MyWorker, %{
record_id: some_record_id
})
assert_enqueued(
[worker: Workers.SecondWorker, args: %{result_id: result.id}],
1000
)
end
And my telemetry event handler looks like this
def handle_event(
[:oban, :job, :stop],
_measure,
meta = %{worker: worker, result: {:ok, result}},
_
) do
Workers.SecondWorker.new(%{result_id: result.id}) |> Oban.insert()
end
However even though I can see the job inserted after inspecting the result of Oban.insert (though it doesn’t have an ID) my test still fails and I couldn’t really figure out why.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
andreyuhai
If I change the Oban config to be
then it works but I don’t know whether there’s any other way of making this work because now some other tests fail.
If I wrap only my test case with
with_testing_mode(:manual...then I getal2o3cr
IIRCI did NOT recall correctly, see @LostKobrakai’s note below.:telemetryhandlers run in a separate process, you may be encountering DB sandbox issues.Also beware: telemetry doesn’t provide any delivery guarantees and aggressively (silently + permanently for the VM’s lifetime) removes listeners that crash even once. If
SecondWorkeris doing anything important, you may want to consider an alternative approach like Oban Pro’s workflows.LostKobrakai
They do not, as they don’t want to introduce message passing.
andreyuhai
I was guessing that those are GenServers and somehow they come back up, but yes, I’ve already encountered that during my tests, so we’ll probably have to switch to Pro to be able to use Workflows. Thank you!
I wonder how other people use it though, I mean if there’s no guarantee and the listeners might get removed. Is it because it doesn’t hurt much (well maybe it does, I have no idea
) losing some metrics?
al2o3cr
Since a crashing handler crashes the calling process, I assume the design principle is “prefer uptime over metrics” which isn’t unreasonable.
It can be kinda painful if you mess up, for instance, a listener that tracks
Oban.Jobcrashes and sends them to Sentry so that you don’t get any reports from production after the very first one. Ask me how I learned THAT oneLostKobrakai
The point here is much more about this:
The code emitting telemetry events can’t handle problems of listeners – those can be libraries, which have no relationship to your project or metric setup. So it’s the job of listeners to have their **** together and deal with any issues they encounter.
trisolaran
Correct, because in
:inlinemode, which is what I assume your original config was using, no jobs are ever enqueued in the DBandreyuhai
But then as I mentioned, even if I wrap it with
with_testing_mode(:manual...I get that argument error I shared above.trisolaran
Most likely because, as the error message suggests,
perform_jobis returning aresultstruct withid=nil.Take a look at what happens in your worker or share the code so someone can help you.
andreyuhai
It wasn’t actually about the result
perform_jobreturns but that happens when Oban tries to complete the job, at least that’s what I understood from stacktrace.Also when I’ve inspected the actual
Oban.Jobthat was passed toperform/1fromperform_job, I see that theidisnil.Not sure that’s because of
). I mean
perform_jobbut I do not think so (or maybeperform_jobdoesn’t actually insert anything as far as I understood by looking at the module.I’m also using
perform_jobin other tests but I’ve never encountered the same error.Edit
Somehow using
perform_jobwithinwith_testing_mode(:manual...causes some problemsThe above snippet somehow throws the ArgumentError I shared above.
I’ve also tried to use
Oban.insert/1instead of usingperform_job/1hoping that it would insert the job and once my job is handled it would enqueue another onebut somehow this way my first job didn’t even get processed. At least I didn’t see the
IO.inspects that I did to ensure it was working the way I assumed it would.how I could finally make it work was by directly calling
perform/1on my workerBut at that point, is this test useful or necessary? Because I am calling
perform/1directly and I already know that if the job is succesfull the next thing it will do is to schedule another one. Maybe that’s the topic of another question about testing in general.