Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions app/jobs/bibliographic_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ class BibliographicJob < ApplicationJob
queue_as :default

def perform(host_bib_task)
current = nil
host_bib_task.host_bibs.where(marc_status: %w[pending retrieving]).find_each do |host_bib|
current = host_bib
Bibliographic::HostBib.create_linked_bibs(host_bib)
end
after_perform_upload!(host_bib_task)
rescue StandardError => e
mark_failed_and_notify!(e, host_bib_task)
mark_failed_and_notify!(e, host_bib_task, current)
end

private
Expand All @@ -25,12 +27,13 @@ def generate_attatchments(host_bib_task)
attachment_hash
end

def mark_failed_and_notify!(e, host_bib_task)
def mark_failed_and_notify!(e, host_bib_task, host_bib)
host_bib_task.failed!
subject = 'Host Bibliographic Upload - Failed'
message = 'Host Bibliographic upload failed, please reach out to our support team.'
RequestMailer.bibliographic_email(host_bib_task.email, [], subject, message).deliver_now
logger.error "BibliographicJob failed: #{e.message}"
RequestMailer.bibliographic_failure_email(host_bib_task.email, subject, host_bib_task, host_bib).deliver_now
mms_id = host_bib&.mms_id
filename = File.basename(host_bib_task.filename)
logger.error "BibliographicJob failed processing #{mms_id} in #{filename}: #{e.message}"
raise e
end

Expand Down
6 changes: 6 additions & 0 deletions app/mailers/request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ def bibliographic_email(email, attachment_contents, subject, body)
mail(to: email, subject:, body:)
end

def bibliographic_failure_email(email, subject, host_bib_task, host_bib)
@host_bib_task = host_bib_task
@host_bib = host_bib
mail(to: email, subject:)
end

def efee_invoice_email(alma_id)
efee = EfeesInvoice.new(alma_id)
# type probably isn't needed now that I spun this off to a separate url
Expand Down
24 changes: 24 additions & 0 deletions app/views/request_mailer/bibliographic_failure_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>

<body>
<br/>
<h1>Upload Failed</h1>
Your Host Bibliographic upload failed. Please reach out to our support team.

<h2>Details</h2>
<dl>
<% if @host_bib_task %>
<dt>Failing file</dt>
<dd><%= File.basename(@host_bib_task.filename) %></dd>
<% end %>
<% if @host_bib %>
<dt>Failing Host MMS ID</dt>
<dd><%= @host_bib.mms_id %></dd>
<% end %>
</dl>
</body>
</html>
10 changes: 10 additions & 0 deletions app/views/request_mailer/bibliographic_failure_email.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Your Host Bibliographic upload failed. Please reach out to our support team.

Failure details:

<% if @host_bib_task %>
Failing file: <%= File.basename(@host_bib_task.filename) %>
<% end %>
<% if @host_bib %>
Failing Host MMS ID: <%= @host_bib.mms_id %>
<% end %>
6 changes: 3 additions & 3 deletions spec/jobs/bibliographic_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
.and_raise(StandardError.new('Error'))

expect(RequestMailer)
.to receive(:bibliographic_email)
.to receive(:bibliographic_failure_email)
.with(
email,
[],
'Host Bibliographic Upload - Failed',
'Host Bibliographic upload failed, please reach out to our support team.'
host_bib_task,
host_bib
).and_return(mailer_double)

expect { BibliographicJob.perform_now(host_bib_task) }.to raise_error(StandardError)
Expand Down
Loading