Rescuing exceptions inside BBM Job Class causing job to not fail properly
Overview
A BBM migration was added with a job class that rescues all the exceptions happening during the job execution. As we wrap job execution, we rely on rescuing errors that happens inside the Job Class to proper fail the job in execution.
Possible Fixes
Doc Updates
-
Update our BBM docs best practices section: Include some information about job classes not to rescue exceptions that happen during the job/batch execution.
# Best
def each_batch do |batch|
batch.update_all(name: 'My Name')
end
# Good
def each_batch do |batch|
batch.update_all(name: 'My Name')
rescue ActiveRecord::Timeout => exception
logger.error(message: e.message, class: self.class.name)
raise
end
# Bad
def each_batch do |batch|
batch.update_all(name: 'My Name')
rescue ActiveRecord::Timeout => exception
logger.error(message: e.message, class: self.class.name)
end
Code Updates
-
Add a Rubocop rule to catch exceptions being rescued without being properly re-raised again inside the Job Class.
Edited by Leonardo da Rosa