Rescue errors in report generation

So we can report them to Bugsnag and the job isn't marked as failed and
therefore won't repeat.
This commit is contained in:
Maikel Linke
2023-10-06 16:27:15 +11:00
parent 17c1ccc509
commit f61a2fa2bf
2 changed files with 17 additions and 0 deletions

View File

@@ -21,6 +21,12 @@ class ReportJob < ApplicationJob
email_result(user, blob) if execution_time > NOTIFICATION_TIME
broadcast_result(channel, format, blob) if channel
rescue StandardError => e
Bugsnag.notify(e) do |payload|
payload.add_metadata :report, {
report_class:, user:, params:, format:
}
end
end
def email_result(user, blob)

View File

@@ -64,6 +64,17 @@ describe ReportJob do
}.to_not enqueue_mail
end
it "rescues errors" do
expect(report_class).to receive(:new).and_raise
expect(Bugsnag).to receive(:notify)
job = ReportJob.perform_later(**report_args)
expect {
perform_enqueued_jobs(only: ReportJob)
}.to_not raise_error
end
def expect_csv_report
blob.reload
expect(blob.filename.to_s).to eq "report.csv"