The ActiveJob docs for exception handling provide this example for how to perform exception handling within the context of a job:
class GuestsCleanupJob < ActiveJob::Base
queue_as :default
rescue_from(ActiveRecord::RecordNotFound) do |exception|
# Do something with the exception
end
def perform
# Do something later
end
end
I am using this technique in an application I am building and capturing certain particular exceptions. My question is, how to capture any and all exceptions?
I am capturing various kinds of exceptions and performing the same procedure each way, so I would like to DRY up my code and also, in my current implementation, certain exceptions are being ignored which means in some cases my job fails silently.
How do I capture any generic exception using ActiveJob?
Try this
class GuestsCleanupJob < ActiveJob::Base
...
rescue_from(StandardError) do |exception|
# Do something with the exception
end
...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With