Skip to content

Commit ffec3ab

Browse files
authored
Merge pull request #1250 from MITLibraries/etd-647-handle-unbaggable-theses
Refactor error handling in Preservation Submission Job
2 parents 7c1ad59 + 4c3f088 commit ffec3ab

File tree

7 files changed

+36
-11
lines changed

7 files changed

+36
-11
lines changed

app/jobs/preservation_submission_job.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ def perform(theses)
66
results = { total: theses.count, processed: 0, errors: [] }
77
theses.each do |thesis|
88
Rails.logger.info("Thesis #{thesis.id} is now being prepared for preservation")
9-
sip = thesis.submission_information_packages.create
9+
sip = thesis.submission_information_packages.create!
1010
preserve_sip(sip)
1111
Rails.logger.info("Thesis #{thesis.id} has been sent to preservation")
1212
results[:processed] += 1
1313
rescue StandardError, Aws::Errors => e
1414
preservation_error = "Thesis #{thesis.id} could not be preserved: #{e}"
1515
Rails.logger.info(preservation_error)
16-
sip.preservation_status = 'error'
17-
sip.save
1816
results[:errors] << preservation_error
1917
end
2018
ReportMailer.preservation_results_email(results).deliver_now if results[:total].positive?

app/models/submission_information_package.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SubmissionInformationPackage < ApplicationRecord
3131

3232
before_create :set_metadata, :set_bag_declaration, :set_manifest, :set_bag_name
3333

34-
enum preservation_status: %i[unpreserved preserved error]
34+
enum preservation_status: %i[unpreserved preserved]
3535

3636
def data
3737
file_locations = {}

test/fixtures/archivematica_accessions.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ june_2018_001:
2828
june_2021_001:
2929
accession_number: '2021_001'
3030
degree_period: june_2021
31+
32+
june_2022_001:
33+
accession_number: '2022_001'
34+
degree_period: june_2022

test/fixtures/degree_periods.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ june_2018:
2828
june_2021:
2929
grad_month: 'June'
3030
grad_year: '2021'
31+
32+
june_2022:
33+
grad_month: 'June'
34+
grad_year: '2022'

test/fixtures/theses.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ engineer:
275275
metadata_complete: true
276276
issues_found: false
277277
publication_status: Published
278+
dspace_handle: '3456/7890'
278279
proquest_exported: 'Full harvest'
279280

280281
long_abstracts_are_fun:

test/jobs/preservation_submission_job_test.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,19 @@ def setup_thesis
3333
end
3434

3535
test 'creates multiple SIPs' do
36-
theses = [setup_thesis, theses(:published)]
36+
thesis_one = setup_thesis
37+
thesis_two = theses(:engineer)
38+
assert_equal 0, thesis_one.submission_information_packages.count
39+
assert_equal 0, thesis_two.submission_information_packages.count
40+
41+
theses = [thesis_one, thesis_two]
42+
PreservationSubmissionJob.perform_now(theses)
43+
assert_equal 1, thesis_one.submission_information_packages.count
44+
assert_equal 1, thesis_two.submission_information_packages.count
45+
46+
PreservationSubmissionJob.perform_now(theses)
47+
assert_equal 2, thesis_one.submission_information_packages.count
48+
assert_equal 2, thesis_two.submission_information_packages.count
3749
end
3850

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

54-
test 'rescues exceptions by updating preservation_status to "error"' do
55-
thesis = theses(:one)
56-
PreservationSubmissionJob.perform_now([thesis])
57-
assert_equal 'error', thesis.submission_information_packages.last.preservation_status
66+
test 'throws exceptions when a thesis is unbaggable' do
67+
assert_raises StandardError do
68+
PreservationSubmissionJob.perform_now([theses[:one]])
69+
end
70+
71+
assert_nothing_raised do
72+
PreservationSubmissionJob.perform_now([setup_thesis])
73+
end
5874
end
5975

60-
test 'does not update preserved_at if the job enters an error state' do
76+
test 'does not create a SIP if the job enters an error state' do
6177
thesis = theses(:one)
78+
assert_empty thesis.submission_information_packages
79+
6280
PreservationSubmissionJob.perform_now([thesis])
63-
assert_nil thesis.submission_information_packages.last.preserved_at
81+
assert_empty thesis.submission_information_packages
6482
end
6583
end

0 commit comments

Comments
 (0)