Class: Spotlight::ProcessBulkUpdatesCsvJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Spotlight::ProcessBulkUpdatesCsvJob
- Includes:
- JobTracking
- Defined in:
- app/jobs/spotlight/process_bulk_updates_csv_job.rb
Instance Method Summary collapse
-
#perform(exhibit, bulk_update) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
Methods included from JobTracking
#finalize_job_tracker!, #initialize_job_tracker!, #job_tracker, #mark_job_as_failed!
Instance Method Details
#perform(exhibit, bulk_update) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/jobs/spotlight/process_bulk_updates_csv_job.rb', line 12 def perform(exhibit, bulk_update) errors = 0 header_converter = ->(header) { header } # Use raw header for columns (since they are configured) csv_path = bulk_update.file.current_path File.open(csv_path) do |f| progress&.total = f.each_line.count(&:present?) - 1 # ignore the header ::CSV.table(f, header_converters: header_converter).each do |row| process_row(exhibit, row) progress&.increment rescue StandardError => e job_tracker.append_log_entry(type: :error, exhibit: exhibit, message: e.to_s) errors += 1 mark_job_as_failed! end exhibit.blacklight_config.repository.connection.commit job_tracker.append_log_entry(type: :info, exhibit: exhibit, message: "#{progress&.progress} of #{progress&.total} (#{errors} errors)") end end |