Return simple values from Oban job
by Paweł Świątkowski
09 Dec 2024
In Oban, a background jobs processor for Elixir, we can return {:error, something}
tuple from the worker’s perform
function. Oban will treat it as a failure, will wrap in an exception (Oban.PerformError
) and will retry it according to its backoff schedule.
It might be tempting to include a lot of information as something
. I did that. I created a nice struct holding all the context of what went wrong - the original params, the steps of execution and finally a detailed message of what went wrong. I returned {:error, %Trace{...}}
and were quite happy…
… until I looked into Sentry. Sentry looked into the returned tuple and created a new issue for every value of the trace. This means a new issue for every job failure. No rollups. Our Sentry was literally flooded with Oban errors and it was impossible to find anything else (it also almost exceeded our quota).
What should I have done instead?
Return simple {:error, :job_failed}
from perform
function. If you need more introspection, log the details and go to you logging service to check them. Don’t rely on an exception to carry all the details, because that might be not how your exception tracker works.