Skip to content

Commit

Permalink
Merge pull request #1250 from MITLibraries/etd-647-handle-unbaggable-…
Browse files Browse the repository at this point in the history
…theses

Refactor error handling in Preservation Submission Job
  • Loading branch information
jazairi committed Nov 21, 2023
2 parents 7c1ad59 + 4c3f088 commit ffec3ab
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
4 changes: 1 addition & 3 deletions app/jobs/preservation_submission_job.rb
Expand Up @@ -6,15 +6,13 @@ def perform(theses)
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
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?
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/models/submission_information_package.rb
Expand Up @@ -31,7 +31,7 @@ class SubmissionInformationPackage < ApplicationRecord

before_create :set_metadata, :set_bag_declaration, :set_manifest, :set_bag_name

enum preservation_status: %i[unpreserved preserved error]
enum preservation_status: %i[unpreserved preserved]

def data
file_locations = {}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/archivematica_accessions.yml
Expand Up @@ -28,3 +28,7 @@ june_2018_001:
june_2021_001:
accession_number: '2021_001'
degree_period: june_2021

june_2022_001:
accession_number: '2022_001'
degree_period: june_2022
4 changes: 4 additions & 0 deletions test/fixtures/degree_periods.yml
Expand Up @@ -28,3 +28,7 @@ june_2018:
june_2021:
grad_month: 'June'
grad_year: '2021'

june_2022:
grad_month: 'June'
grad_year: '2022'
1 change: 1 addition & 0 deletions test/fixtures/theses.yml
Expand Up @@ -275,6 +275,7 @@ engineer:
metadata_complete: true
issues_found: false
publication_status: Published
dspace_handle: '3456/7890'
proquest_exported: 'Full harvest'

long_abstracts_are_fun:
Expand Down
32 changes: 25 additions & 7 deletions test/jobs/preservation_submission_job_test.rb
Expand Up @@ -33,7 +33,19 @@ def setup_thesis
end

test 'creates multiple SIPs' do
theses = [setup_thesis, theses(:published)]
thesis_one = setup_thesis
thesis_two = theses(:engineer)
assert_equal 0, thesis_one.submission_information_packages.count
assert_equal 0, thesis_two.submission_information_packages.count

theses = [thesis_one, thesis_two]
PreservationSubmissionJob.perform_now(theses)
assert_equal 1, thesis_one.submission_information_packages.count
assert_equal 1, thesis_two.submission_information_packages.count

PreservationSubmissionJob.perform_now(theses)
assert_equal 2, thesis_one.submission_information_packages.count
assert_equal 2, thesis_two.submission_information_packages.count
end

test 'updates preservation_status to "preserved" after successfully processing a thesis' do
Expand All @@ -51,15 +63,21 @@ def setup_thesis
end
end

test 'rescues exceptions by updating preservation_status to "error"' do
thesis = theses(:one)
PreservationSubmissionJob.perform_now([thesis])
assert_equal 'error', thesis.submission_information_packages.last.preservation_status
test 'throws exceptions when a thesis is unbaggable' do
assert_raises StandardError do
PreservationSubmissionJob.perform_now([theses[:one]])
end

assert_nothing_raised do
PreservationSubmissionJob.perform_now([setup_thesis])
end
end

test 'does not update preserved_at if the job enters an error state' do
test 'does not create a SIP if the job enters an error state' do
thesis = theses(:one)
assert_empty thesis.submission_information_packages

PreservationSubmissionJob.perform_now([thesis])
assert_nil thesis.submission_information_packages.last.preserved_at
assert_empty thesis.submission_information_packages
end
end

0 comments on commit ffec3ab

Please sign in to comment.