From 94b3eab8e566f16a9b20cc655615b5bc128c8cca Mon Sep 17 00:00:00 2001 From: jazairi <16103405+jazairi@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:19:47 -0500 Subject: [PATCH] Add report emails to preservation workflow Why these changes are being introduced: We found a bug in the preservation workflow last month that we might have identified sooner if the preservation submission job triggered a report email. Relevant ticket(s): https://mitlibraries.atlassian.net/browse/ETD-651 How this addresses that need: * Removes the Preservation Submission Prep Job * Updates the Preservation Submission Job to accept an array of theses * Adds a preservation results email to the Report Mailer that is enqueued on completion of the Preservation Submission Job * Updates the preservation rake task to convert the input thesis into an array, so it will continue to work Side effects of this change: We not sure why we implemented the 'prep' job pattern: passing in an array of theses so the actual job takes a single thesis as a parameter. There is some risk in removing this job, since we don't remember why it exists in the first place. --- app/jobs/dspace_publication_results_job.rb | 2 +- app/jobs/preservation_submission_job.rb | 26 +++++++++++------ app/jobs/preservation_submission_prep_job.rb | 11 -------- app/mailers/report_mailer.rb | 10 +++++++ .../preservation_results_email.html.erb | 21 ++++++++++++++ lib/tasks/preservation.rake | 2 +- .../dspace_publication_results_job_test.rb | 2 +- .../preservation_submission_job_prep_test.rb | 28 ------------------- test/jobs/preservation_submission_job_test.rb | 22 +++++++++++---- test/mailers/report_mailer_test.rb | 19 +++++++++++++ 10 files changed, 87 insertions(+), 56 deletions(-) delete mode 100644 app/jobs/preservation_submission_prep_job.rb create mode 100644 app/views/report_mailer/preservation_results_email.html.erb delete mode 100644 test/jobs/preservation_submission_job_prep_test.rb diff --git a/app/jobs/dspace_publication_results_job.rb b/app/jobs/dspace_publication_results_job.rb index 91a09cee..d4dbee7f 100644 --- a/app/jobs/dspace_publication_results_job.rb +++ b/app/jobs/dspace_publication_results_job.rb @@ -19,7 +19,7 @@ def perform results[:errors] << "Error reading from SQS queue: #{e}" end - PreservationSubmissionPrepJob.perform_later(results[:preservation_ready]) if results[:preservation_ready].any? + PreservationSubmissionJob.perform_later(results[:preservation_ready]) if results[:preservation_ready].any? MarcExportJob.perform_later(results[:marc_exports]) if results[:marc_exports].any? ReportMailer.publication_results_email(results).deliver_now if results[:total].positive? || results[:errors].any? diff --git a/app/jobs/preservation_submission_job.rb b/app/jobs/preservation_submission_job.rb index 4c615ec5..053a1575 100644 --- a/app/jobs/preservation_submission_job.rb +++ b/app/jobs/preservation_submission_job.rb @@ -1,15 +1,23 @@ class PreservationSubmissionJob < ActiveJob::Base queue_as :default - def perform(thesis) - Rails.logger.info("Thesis #{thesis.id} is now being prepared for preservation") - sip = thesis.submission_information_packages.create - preserve_sip(sip) - Rails.logger.info("Thesis #{thesis.id} has been sent to preservation") - rescue StandardError, Aws::Errors => e - Rails.logger.info("Thesis #{thesis.id} could not be preserved: #{e}") - sip.preservation_status = 'error' - sip.save + def perform(theses) + Rails.logger.info("Preparing to send #{theses.count} theses to preservation") + results = { total: theses.count, processed: 0, errors: [] } + theses.each do |thesis| + Rails.logger.info("Thesis #{thesis.id} is now being prepared for preservation") + sip = thesis.submission_information_packages.create + preserve_sip(sip) + Rails.logger.info("Thesis #{thesis.id} has been sent to preservation") + results[:processed] += 1 + rescue StandardError, Aws::Errors => e + preservation_error = "Thesis #{thesis.id} could not be preserved: #{e}" + Rails.logger.info(preservation_error) + sip.preservation_status = 'error' + sip.save + results[:errors] << preservation_error + end + ReportMailer.preservation_results_email(results).deliver_now if results[:total].positive? end private diff --git a/app/jobs/preservation_submission_prep_job.rb b/app/jobs/preservation_submission_prep_job.rb deleted file mode 100644 index da9a2da4..00000000 --- a/app/jobs/preservation_submission_prep_job.rb +++ /dev/null @@ -1,11 +0,0 @@ -class PreservationSubmissionPrepJob < ActiveJob::Base - queue_as :default - - def perform(theses) - Rails.logger.info("Preparing to send #{theses.count} theses to preservation") - - theses.each do |thesis| - PreservationSubmissionJob.perform_later(thesis) - end - end -end diff --git a/app/mailers/report_mailer.rb b/app/mailers/report_mailer.rb index 8b12b7ce..9b15344f 100644 --- a/app/mailers/report_mailer.rb +++ b/app/mailers/report_mailer.rb @@ -19,4 +19,14 @@ def publication_results_email(results) cc: ENV['MAINTAINER_EMAIL'], subject: 'DSpace publication results summary') end + + def preservation_results_email(results) + return unless ENV.fetch('DISABLE_ALL_EMAIL', 'true') == 'false' # allows PR builds to disable emails + + @results = results + mail(from: "MIT Libraries <#{ENV['ETD_APP_EMAIL']}>", + to: ENV['THESIS_ADMIN_EMAIL'], + cc: ENV['MAINTAINER_EMAIL'], + subject: 'Archivematica preservation submission results summary') + end end diff --git a/app/views/report_mailer/preservation_results_email.html.erb b/app/views/report_mailer/preservation_results_email.html.erb new file mode 100644 index 00000000..17107077 --- /dev/null +++ b/app/views/report_mailer/preservation_results_email.html.erb @@ -0,0 +1,21 @@ +
Hello,
+ +Below is a report of the Archivematica preservation submission job.
+ +Summary of results:
+ +The following errors require processor attention:
+ +