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

🐛 Fix FileSet csv rows for AF imports #954

Merged
merged 1 commit into from
May 10, 2024
Merged
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
35 changes: 18 additions & 17 deletions app/jobs/bulkrax/import_file_set_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ def perform(entry_id, importer_run_id)
# e.g. "parents" or "parents_1"
parent_identifier = (entry.raw_metadata[entry.related_parents_raw_mapping] || entry.raw_metadata["#{entry.related_parents_raw_mapping}_1"])&.strip

validate_parent!(parent_identifier)
begin
validate_parent!(parent_identifier)
rescue MissingParentError => e
handle_retry(entry, importer_run_id, e)
return
end

entry.build
if entry.succeeded?
Expand All @@ -32,17 +37,6 @@ def perform(entry_id, importer_run_id)
entry.save!
entry.importer.current_run = ImporterRun.find(importer_run_id)
entry.importer.record_status

rescue MissingParentError => e
# try waiting for the parent record to be created
entry.import_attempts += 1
entry.save!
if entry.import_attempts < 5
ImportFileSetJob.set(wait: (entry.import_attempts + 1).minutes).perform_later(entry_id, importer_run_id)
else
ImporterRun.decrement_counter(:enqueued_records, importer_run_id) # rubocop:disable Rails/SkipsModelValidations
entry.set_status_info(e)
end
end

private
Expand All @@ -54,14 +48,9 @@ def validate_parent!(parent_identifier)
return if parent_identifier.blank?

find_parent_record(parent_identifier)
check_parent_exists!(parent_identifier)
check_parent_is_a_work!(parent_identifier)
end

def check_parent_exists!(parent_identifier)
raise MissingParentError, %(Unable to find a record with the identifier "#{parent_identifier}") if parent_record.nil?
end

def check_parent_is_a_work!(parent_identifier)
case parent_record
when Bulkrax.collection_model_class, Bulkrax.file_model_class
Expand All @@ -72,6 +61,18 @@ def check_parent_is_a_work!(parent_identifier)

def find_parent_record(parent_identifier)
_, @parent_record = find_record(parent_identifier, importer_run_id)
raise MissingParentError, %(Unable to find a record with the identifier "#{parent_identifier}") unless parent_record
end

def handle_retry(entry, importer_run_id, e)
entry.import_attempts += 1
entry.save!
if entry.import_attempts < 5
ImportFileSetJob.set(wait: (entry.import_attempts + 1).minutes).perform_later(entry.id, importer_run_id)
else
ImporterRun.decrement_counter(:enqueued_records, importer_run_id) # rubocop:disable Rails/SkipsModelValidations
entry.set_status_info(e)
end
end
end
end
Loading