app/jobs/bulkrax/create_relationships_job.rb in bulkrax-3.0.0.beta3 vs app/jobs/bulkrax/create_relationships_job.rb in bulkrax-3.0.0.beta4

- old
+ new

@@ -35,15 +35,15 @@ pending_relationships = Bulkrax::PendingRelationship.find_each.select do |rel| rel.bulkrax_importer_run_id == importer_run_id && rel.parent_id == parent_identifier end.sort_by(&:order) @importer_run_id = importer_run_id - @parent_record = find_record(parent_identifier) + @parent_entry, @parent_record = find_record(parent_identifier, importer_run_id) @child_records = { works: [], collections: [] } pending_relationships.each do |rel| raise ::StandardError, %("#{rel}" needs either a child or a parent to create a relationship) if rel.child_id.nil? || rel.parent_id.nil? - child_record = find_record(rel.child_id) + _, child_record = find_record(rel.child_id, importer_run_id) child_record.is_a?(::Collection) ? @child_records[:collections] << child_record : @child_records[:works] << child_record end if (child_records[:collections].blank? && child_records[:works].blank?) || parent_record.blank? reschedule( @@ -51,13 +51,13 @@ importer_run_id: importer_run_id ) return false # stop current job from continuing to run after rescheduling end - @parent_entry = Bulkrax::Entry.where(identifier: parent_identifier, - importerexporter_id: ImporterRun.find(importer_run_id).importer_id, - importerexporter_type: "Bulkrax::Importer").first + @parent_entry ||= Bulkrax::Entry.where(identifier: parent_identifier, + importerexporter_id: ImporterRun.find(importer_run_id).importer_id, + importerexporter_type: "Bulkrax::Importer").first create_relationships pending_relationships.each(&:destroy) rescue ::StandardError => e parent_entry.status_info(e) Bulkrax::ImporterRun.find(importer_run_id).increment!(:failed_relationships) # rubocop:disable Rails/SkipsModelValidations @@ -89,11 +89,12 @@ source_identifier_value: nil, # sending the :id in the attrs means the factory doesn't need a :source_identifier_value work_identifier: parent_entry.parser.work_identifier, related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping, replace_files: false, user: user, - klass: child_record.class + klass: child_record.class, + importer_run_id: importer_run_id ).run # TODO: add counters for :processed_parents and :failed_parents Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations end end @@ -107,11 +108,12 @@ source_identifier_value: nil, # sending the :id in the attrs means the factory doesn't need a :source_identifier_value work_identifier: parent_entry.parser.work_identifier, related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping, replace_files: false, user: user, - klass: parent_record.class + klass: parent_record.class, + importer_run_id: importer_run_id ).run # TODO: add counters for :processed_parents and :failed_parents Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations end @@ -130,10 +132,11 @@ source_identifier_value: nil, # sending the :id in the attrs means the factory doesn't need a :source_identifier_value work_identifier: parent_entry.parser.work_identifier, related_parents_parsed_mapping: parent_entry.parser.related_parents_parsed_mapping, replace_files: false, user: user, - klass: parent_record.class + klass: parent_record.class, + importer_run_id: importer_run_id ).run # TODO: add counters for :processed_parents and :failed_parents Bulkrax::ImporterRun.find(importer_run_id).increment!(:processed_relationships) # rubocop:disable Rails/SkipsModelValidations end