Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor error handling in Preservation Submission Job #1250

Merged
merged 1 commit into from
Nov 21, 2023
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
4 changes: 1 addition & 3 deletions app/jobs/preservation_submission_job.rb
Original file line number Diff line number Diff line change
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
JPrevost marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading