mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #11657 from mkllnk/report-job-retries
Notify user about errors raised in reports
This commit is contained in:
@@ -21,6 +21,14 @@ 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
|
||||
|
||||
broadcast_error(channel)
|
||||
end
|
||||
|
||||
def email_result(user, blob)
|
||||
@@ -37,6 +45,13 @@ class ReportJob < ApplicationJob
|
||||
).broadcast
|
||||
end
|
||||
|
||||
def broadcast_error(channel)
|
||||
cable_ready[channel].inner_html(
|
||||
selector: "#report-table",
|
||||
html: I18n.t("report_job.report_failed")
|
||||
).broadcast
|
||||
end
|
||||
|
||||
def actioncable_content(format, blob)
|
||||
return blob.result if format.to_sym == :html
|
||||
|
||||
|
||||
@@ -335,6 +335,10 @@ en:
|
||||
not_array_error: "must be an array"
|
||||
invalid_element_error: "must contain only valid integers"
|
||||
|
||||
report_job:
|
||||
report_failed: |
|
||||
This report failed. It may be too big to process.
|
||||
We will look into it but please let us know if the problem persists.
|
||||
enterprise_mailer:
|
||||
confirmation_instructions:
|
||||
subject: "Please confirm the email address for %{enterprise}"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user