AE
Ash Elixirโ€ข4d ago
mcoll

AshOban job failures

I have a job that runs using AshOban, which I find a very nice way of doing things tbh, as most things you've done so far! However it seems to me that the only way to handle failures is to give it an action to run. For example setting the state to failed, however I'd like to be able to see the failure in Oban apart from setting the Resource as failed. I have scoured the documentation but I don't see a way of having the Oban job fail on failure. Am I missing something? Was there a specific reason this is like this?
14 Replies
ZachDaniel
ZachDanielโ€ข4d ago
๐Ÿค” Its a bit complex because we don't want the job to be retried or anything like that. I think we could change it to show the jobs as failed but it would require some way to return that from a job like "this failed, but discard it" or something like that
mcoll
mcollOPโ€ข4d ago
Ah, I see. Basically you want to bypass Oban retry system. Since you are handling it yourselves Are you using Oban.Worker under the hood? Maybe max_attempts could be set such that that doesn't happen? Or that didn't work?
ZachDaniel
ZachDanielโ€ข4d ago
Correct, we do. So actually it may not be an issue now that you bring it up ๐Ÿค” because we just intercept when we are on the last attempt So maybe we actually can just let it fail Yeah, okay, so if you want to experiment with this, you could try cloning down ash_oban and in define_schedulers (sorry for the state of that file), in this function head:
def handle_error(
%{max_attempts: max_attempts, attempt: max_attempts, args: args} = job,
error,
primary_key,
stacktrace
) do
def handle_error(
%{max_attempts: max_attempts, attempt: max_attempts, args: args} = job,
error,
primary_key,
stacktrace
) do
We just need to reraise the error at the end instead of doing :ok
mcoll
mcollOPโ€ข4d ago
okay, will try later tonight ๐Ÿ™‚
ZachDaniel
ZachDanielโ€ข4d ago
lines 720/723-ish
mcoll
mcollOPโ€ข4d ago
okay, it seems to work, will clean it up and may send a PR later do we want to enable this behaviour all the time, or should we make it a configuration of the trigger?
ZachDaniel
ZachDanielโ€ข4d ago
For now we should make it opt in so as not to break applications But make a command that includes the next major version number and we can change the default to be this new behavior
mcoll
mcollOPโ€ข4d ago
okay, so I can add a "fail_job_on_error" boolean, with default false
ZachDaniel
ZachDanielโ€ข4d ago
Yep. Although we may want to be careful with the wording Because if there is no on_error then it does fail ๐Ÿ˜‚
mcoll
mcollOPโ€ข4d ago
maybe just fail_jobs? (although ash_oban is at 0.4.6, which means that under semver you are allowed to make breaking changes in minor versions ๐Ÿ™ƒ )
ZachDaniel
ZachDanielโ€ข4d ago
๐Ÿ˜† still prefer not to ๐Ÿ˜†
mcoll
mcollOPโ€ข4d ago
of course of course ๐Ÿ˜„
mcoll
mcollOPโ€ข4d ago
GitHub
feat: Implement :fail_oban_job? option for triggers by MarceColl ยท...
By default AshOban doesn't fail the Oban job, this new option gives users the control wether they want to fail the job or not. Contributor checklist Features include unit/acceptance tests
mcoll
mcollOPโ€ข4d ago
Let me know if I'm missing anything important

Did you find this page helpful?