In ActiveJob, how to catch any exception

ActiveJob docs for exception handling provide this example for how to handle exception handling in 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 use this technique in an application that I create and catch certain exceptions. My question is: how to fix all exceptions?

I deal with various exceptions and execute the same procedure every time, so I would like to DRY my code, and in my current implementation some exceptions are ignored, which means that in some cases my work fails.

How to get any general exception using ActiveJob?

+6
source share
1 answer

try it

 class GuestsCleanupJob < ActiveJob::Base ... rescue_from(StandardError) do |exception| # Do something with the exception end ... end 
+12
source

All Articles