Skip to content

Commit 56c76ad

Browse files
committed
cherry-pick ImportFileSetJob retry logic from 0de8ee06
1 parent e00fd94 commit 56c76ad

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

app/jobs/bulkrax/import_file_set_job.rb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ def perform(entry_id, importer_run_id)
1616
# e.g. "parents" or "parents_1"
1717
parent_identifier = (entry.raw_metadata[entry.related_parents_raw_mapping] || entry.raw_metadata["#{entry.related_parents_raw_mapping}_1"])&.strip
1818

19-
validate_parent!(parent_identifier)
19+
begin
20+
validate_parent!(parent_identifier)
21+
rescue MissingParentError => e
22+
handle_retry(entry, importer_run_id, e)
23+
return
24+
end
2025

2126
entry.build
2227
if entry.succeeded?
@@ -32,17 +37,6 @@ def perform(entry_id, importer_run_id)
3237
entry.save!
3338
entry.importer.current_run = ImporterRun.find(importer_run_id)
3439
entry.importer.record_status
35-
36-
rescue MissingParentError => e
37-
# try waiting for the parent record to be created
38-
entry.import_attempts += 1
39-
entry.save!
40-
if entry.import_attempts < 5
41-
ImportFileSetJob.set(wait: (entry.import_attempts + 1).minutes).perform_later(entry_id, importer_run_id)
42-
else
43-
ImporterRun.decrement_counter(:enqueued_records, importer_run_id) # rubocop:disable Rails/SkipsModelValidations
44-
entry.set_status_info(e)
45-
end
4640
end
4741

4842
private
@@ -54,21 +48,28 @@ def validate_parent!(parent_identifier)
5448
return if parent_identifier.blank?
5549

5650
find_parent_record(parent_identifier)
57-
check_parent_exists!(parent_identifier)
5851
check_parent_is_a_work!(parent_identifier)
5952
end
6053

61-
def check_parent_exists!(parent_identifier)
62-
raise MissingParentError, %(Unable to find a record with the identifier "#{parent_identifier}") if parent_record.nil?
63-
end
64-
6554
def check_parent_is_a_work!(parent_identifier)
6655
error_msg = %(A record with the ID "#{parent_identifier}" was found, but it was a #{parent_record.class}, which is not an valid/available work type)
6756
raise ::StandardError, error_msg unless curation_concern?(parent_record)
6857
end
6958

7059
def find_parent_record(parent_identifier)
7160
_, @parent_record = find_record(parent_identifier, importer_run_id)
61+
raise MissingParentError, %(Unable to find a record with the identifier "#{parent_identifier}") unless parent_record
62+
end
63+
64+
def handle_retry(entry, importer_run_id, e)
65+
entry.import_attempts += 1
66+
entry.save!
67+
if entry.import_attempts < 5
68+
ImportFileSetJob.set(wait: (entry.import_attempts + 1).minutes).perform_later(entry.id, importer_run_id)
69+
else
70+
ImporterRun.decrement_counter(:enqueued_records, importer_run_id) # rubocop:disable Rails/SkipsModelValidations
71+
entry.set_status_info(e)
72+
end
7273
end
7374
end
7475
end

0 commit comments

Comments
 (0)