Skip to content
Snippets Groups Projects
Commit c6e48414 authored by Anusha Ranganathan's avatar Anusha Ranganathan
Browse files

Add helper to rerun last import run

parent af9a049f
Branches
Tags
1 merge request!301Add helper to rerun last import run
Pipeline #14207 failed
......@@ -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
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment