Skip to content

Commit cc61417

Browse files
committed
BibliographicJob: Improve failure handling
* Return the currently-processing host_bib on failure, when available. * Separate the failure into its own mailer, and ensure the template includes both the failing text file and, if available, the specific MMS ID that failed. * Report that information to the error logger as well. * Amend tests to cover this new functionality. Closes: AP-778
1 parent a617ac2 commit cc61417

5 files changed

Lines changed: 51 additions & 8 deletions

File tree

app/jobs/bibliographic_job.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ class BibliographicJob < ApplicationJob
22
queue_as :default
33

44
def perform(host_bib_task)
5+
current = nil
56
host_bib_task.host_bibs.where(marc_status: %w[pending retrieving]).find_each do |host_bib|
7+
current = host_bib
68
Bibliographic::HostBib.create_linked_bibs(host_bib)
79
end
810
after_perform_upload!(host_bib_task)
911
rescue StandardError => e
10-
mark_failed_and_notify!(e, host_bib_task)
12+
mark_failed_and_notify!(e, host_bib_task, current)
1113
end
1214

1315
private
@@ -25,12 +27,13 @@ def generate_attatchments(host_bib_task)
2527
attachment_hash
2628
end
2729

28-
def mark_failed_and_notify!(e, host_bib_task)
30+
def mark_failed_and_notify!(e, host_bib_task, host_bib)
2931
host_bib_task.failed!
3032
subject = 'Host Bibliographic Upload - Failed'
31-
message = 'Host Bibliographic upload failed, please reach out to our support team.'
32-
RequestMailer.bibliographic_email(host_bib_task.email, [], subject, message).deliver_now
33-
logger.error "BibliographicJob failed: #{e.message}"
33+
RequestMailer.bibliographic_failure_email(host_bib_task.email, subject, host_bib_task, host_bib).deliver_now
34+
mms_id = host_bib&.mms_id
35+
filename = File.basename(host_bib_task.filename)
36+
logger.error "BibliographicJob failed processing #{mms_id} in #{filename}: #{e.message}"
3437
raise e
3538
end
3639

app/mailers/request_mailer.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,12 @@ def bibliographic_email(email, attachment_contents, subject, body)
232232
mail(to: email, subject:, body:)
233233
end
234234

235+
def bibliographic_failure_email(email, subject, host_bib_task, host_bib)
236+
@host_bib_task = host_bib_task
237+
@host_bib = host_bib
238+
mail(to: email, subject:)
239+
end
240+
235241
def efee_invoice_email(alma_id)
236242
efee = EfeesInvoice.new(alma_id)
237243
# type probably isn't needed now that I spun this off to a separate url
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
5+
</head>
6+
7+
<body>
8+
<br/>
9+
<h1>Upload Failed</h1>
10+
Your Host Bibliographic upload failed. Please reach out to our support team.
11+
12+
<h2>Details</h2>
13+
<dl>
14+
<% if @host_bib_task %>
15+
<dt>Failing file</dt>
16+
<dd><%= File.basename(@host_bib_task.filename) %></dd>
17+
<% end %>
18+
<% if @host_bib %>
19+
<dt>Failing Host MMS ID</dt>
20+
<dd><%= @host_bib.mms_id %></dd>
21+
<% end %>
22+
</dl>
23+
</body>
24+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Your Host Bibliographic upload failed. Please reach out to our support team.
2+
3+
Failure details:
4+
5+
<% if @host_bib_task %>
6+
Failing file: <%= File.basename(@host_bib_task.filename) %>
7+
<% end %>
8+
<% if @host_bib %>
9+
Failing Host MMS ID: <%= @host_bib.mms_id %>
10+
<% end %>

spec/jobs/bibliographic_job_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@
7373
.and_raise(StandardError.new('Error'))
7474

7575
expect(RequestMailer)
76-
.to receive(:bibliographic_email)
76+
.to receive(:bibliographic_failure_email)
7777
.with(
7878
email,
79-
[],
8079
'Host Bibliographic Upload - Failed',
81-
'Host Bibliographic upload failed, please reach out to our support team.'
80+
host_bib_task,
81+
host_bib
8282
).and_return(mailer_double)
8383

8484
expect { BibliographicJob.perform_now(host_bib_task) }.to raise_error(StandardError)

0 commit comments

Comments
 (0)