Hi,
ActiveJob exception handing can be performed using ‘retry_on’ and ‘discard_on’. To use the default exception handlers you can write:
retry_on(CustomAppException)
discard_on(AnotherCustomAppException)
To use custom exception handling with ‘retry_on’:
retry_on(CustomAppException) do |job, exception|
ExceptionNotifier.caught(exception)
end
However, you cannot currently use custom exception handling with ‘discard_on’ as the passed block isn’t called.
discard_on(AnotherCustomAppException) do |job, exception|
ExceptionNotifier.caught(exception) ### DOES NOT GET CALLED ###
end
Instead you have to write:
retry_on(AnotherCustomAppException, attempts: 1) do |job, exception|
ExceptionNotifier.caught(exception)
end
or
rescue_from(AnotherCustomAppException) do |exception|
ExceptionNotifier.caught(exception)
end
Would be nicer if the blocked passed to ‘discard_on’ was called and the following worked:
discard_on(AnotherCustomAppException) do |job, exception|
ExceptionNotifier.caught(exception)
end
I’ve made this PR with the required changes: Allow for custom handling of exceptions that are discarded by aidanharan · Pull Request #30622 · rails/rails · GitHub
Thanks,
Aidan