marcin

marcin

Oban: error handling and job retry

I’m implementing a controller that schedules a background job and returns.
The job itself is implemented as a GenServer Foo.

I wanted this to be reliable, so that if Foo fails, it is restarted, different Foo jobs are distributed, and that I have a track record of what went wrong and right.
Coming from ruby I wanted similar guarantees to Sidekiq, and so I decided I’ll use Oban workers.

I created an Oban worker that start_links to the GenServer Foo and waits using receive for a message from Foo, that it has completed its job.

I thought that if Foo dies, the worker will die as well and Oban will restart it. Wrong: Oban worker will only be restarted if it raises and error, not if it gets killed.

So instead, i did Process.monitor on Foo’s pid, and I’m checking if the message from Foo is the completion message, or : DOWN message. If it’s the latter, I’m raising an exception so Oban retries this job later.

This works but I feel like suddenly I’m implementing some kind of supervisor mechanism and I should probably use mechanisms that are already present in Elixir. What would you suggest here? Also the necessity to pass “call me back” pid to Foo so it sends back information about successful completion seems like unnecessary coupling. Maybe this is not the case for using Oban?

For those interested in details: the job is to download a huge file and process it. The controller endpoint just accepts the URL of huge file and schedules this job.

Marked As Solved

sorentwo

sorentwo

Oban Core Team

Is this the only place you’re using the Foo gen server? If so, perhaps you don’t need to use a separate GenServer or process at all. Each job in Oban runs as an isolated process already.

This can work, you’d just need to call Process.flag(:trap_exit, true) within the Oban job to ensure that it receives an :EXIT, pid, reason message rather than crashing the process. By default Oban jobs do not trap exits.


Sending messages between processes will always add a little bit of complexity: passing pids, sending messages and monitoring are par for the course. If possible, I’d first try to put all of this within a single process. Failing that, I would try to use a Task rather than a GenServer and simplify the message passing.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Other popular topics Top

jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement