@@ -16,7 +16,12 @@ def perform(entry_id, importer_run_id)
16
16
# e.g. "parents" or "parents_1"
17
17
parent_identifier = ( entry . raw_metadata [ entry . related_parents_raw_mapping ] || entry . raw_metadata [ "#{ entry . related_parents_raw_mapping } _1" ] ) &.strip
18
18
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
20
25
21
26
entry . build
22
27
if entry . succeeded?
@@ -32,17 +37,6 @@ def perform(entry_id, importer_run_id)
32
37
entry . save!
33
38
entry . importer . current_run = ImporterRun . find ( importer_run_id )
34
39
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
46
40
end
47
41
48
42
private
@@ -54,21 +48,28 @@ def validate_parent!(parent_identifier)
54
48
return if parent_identifier . blank?
55
49
56
50
find_parent_record ( parent_identifier )
57
- check_parent_exists! ( parent_identifier )
58
51
check_parent_is_a_work! ( parent_identifier )
59
52
end
60
53
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
-
65
54
def check_parent_is_a_work! ( parent_identifier )
66
55
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)
67
56
raise ::StandardError , error_msg unless curation_concern? ( parent_record )
68
57
end
69
58
70
59
def find_parent_record ( parent_identifier )
71
60
_ , @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
72
73
end
73
74
end
74
75
end
0 commit comments