diff --git a/app/jobs/bibliographic_job.rb b/app/jobs/bibliographic_job.rb index 3920f7fc..c679e6df 100644 --- a/app/jobs/bibliographic_job.rb +++ b/app/jobs/bibliographic_job.rb @@ -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 @@ -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 diff --git a/app/mailers/request_mailer.rb b/app/mailers/request_mailer.rb index 17ec7384..02b7f73c 100644 --- a/app/mailers/request_mailer.rb +++ b/app/mailers/request_mailer.rb @@ -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 diff --git a/app/views/request_mailer/bibliographic_failure_email.html.erb b/app/views/request_mailer/bibliographic_failure_email.html.erb new file mode 100644 index 00000000..ed37c6f9 --- /dev/null +++ b/app/views/request_mailer/bibliographic_failure_email.html.erb @@ -0,0 +1,24 @@ + + + + + + + +
+

Upload Failed

+ Your Host Bibliographic upload failed. Please reach out to our support team. + +

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 %> +
+ + diff --git a/app/views/request_mailer/bibliographic_failure_email.text.erb b/app/views/request_mailer/bibliographic_failure_email.text.erb new file mode 100644 index 00000000..c7b925dc --- /dev/null +++ b/app/views/request_mailer/bibliographic_failure_email.text.erb @@ -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 %> diff --git a/spec/jobs/bibliographic_job_spec.rb b/spec/jobs/bibliographic_job_spec.rb index b33cdffd..11c64ce5 100644 --- a/spec/jobs/bibliographic_job_spec.rb +++ b/spec/jobs/bibliographic_job_spec.rb @@ -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)