diff --git a/hyrax/app/controllers/bulkrax/rerun_importers_controller.rb b/hyrax/app/controllers/bulkrax/rerun_importers_controller.rb index 42420c1383c1c39abd3f895760eafdd29d624a78..a23670764ebbca5c11241c381bc5907d16aafb9d 100644 --- a/hyrax/app/controllers/bulkrax/rerun_importers_controller.rb +++ b/hyrax/app/controllers/bulkrax/rerun_importers_controller.rb @@ -2,58 +2,11 @@ module Bulkrax class RerunImportersController < ApplicationController + include BulkraxHelper before_action :set_importer, only: [:rerun_failed_entries, :marked_as_complete] def rerun_failed_entries - current_run = @importer.last_run - - if current_run&.failed_records&.positive? - ScheduleRelationshipsJob.set(wait: 5.minutes).perform_later(importer_id: @importer.id) - @importer.status_info('Pending') - - @importer.entries.each do |entry| - next if entry.status == 'Complete' - - type = if entry.raw_metadata['model'] == 'CrcDataset' - 'Work' - else - entry.raw_metadata['model'] - end - - entry.status_info('Pending') - current_run.decrement!(:failed_records) - current_run.increment!(:enqueued_records) - - if type == 'Collection' - current_run.decrement!(:failed_collections) - elsif type == 'Work' - current_run.decrement!(:failed_works) - elsif type == 'FileSet' - current_run.decrement!(:failed_file_sets) - elsif type == 'ComplexSubject' - current_run.decrement!(:failed_complex_subjects) - elsif type == 'ComplexSession' - current_run.decrement!(:failed_complex_sessions) - elsif type == 'ComplexModality' - current_run.decrement!(:failed_complex_modalities) - end - - "Bulkrax::CrcDataset::Import#{type}Job".constantize.send( - entry.parser.perform_method, - entry.id, - @importer.importer_runs.last.id - ) - end - - current_run.save - - elsif current_run && @importer.parser.total.positive? && current_run.processed_records.zero? - Bulkrax::ImporterJob.send( - @importer.parser.perform_method, - @importer.id - ) - end - + rerun_failed_entries_in_last_run redirect_to importers_path end diff --git a/hyrax/app/helpers/bulkrax_helper.rb b/hyrax/app/helpers/bulkrax_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..996117e2827de4ba8ac135920a00bd5eaffabf40 --- /dev/null +++ b/hyrax/app/helpers/bulkrax_helper.rb @@ -0,0 +1,52 @@ +module BulkraxHelper + def rerun_failed_entries_in_last_run + current_run = @importer.last_run + + if current_run&.failed_records&.positive? + ScheduleRelationshipsJob.set(wait: 5.minutes).perform_later(importer_id: @importer.id) + @importer.status_info('Pending') + + @importer.entries.each do |entry| + next if entry.status == 'Complete' + + type = if entry.raw_metadata['model'] == 'CrcDataset' + 'Work' + else + entry.raw_metadata['model'] + end + + entry.status_info('Pending') + current_run.decrement!(:failed_records) + current_run.increment!(:enqueued_records) + + if type == 'Collection' + current_run.decrement!(:failed_collections) + elsif type == 'Work' + current_run.decrement!(:failed_works) + elsif type == 'FileSet' + current_run.decrement!(:failed_file_sets) + elsif type == 'ComplexSubject' + current_run.decrement!(:failed_complex_subjects) + elsif type == 'ComplexSession' + current_run.decrement!(:failed_complex_sessions) + elsif type == 'ComplexModality' + current_run.decrement!(:failed_complex_modalities) + end + + "Bulkrax::CrcDataset::Import#{type}Job".constantize.send( + entry.parser.perform_method, + entry.id, + @importer.importer_runs.last.id + ) + end + + current_run.save + + elsif current_run && @importer.parser.total.positive? && current_run.processed_records.zero? + Bulkrax::ImporterJob.send( + @importer.parser.perform_method, + @importer.id + ) + end + end +end \ No newline at end of file