Sha256: 5b67c7cab52a627b37d005f2694ee7779fcf985922cfe40b86e6cda61c896ff4

Contents?: true

Size: 1.33 KB

Versions: 8

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Bulkrax
  class ImporterJob < ApplicationJob
    queue_as :import

    def perform(importer_id, only_updates_since_last_import = false)
      importer = Importer.find(importer_id)

      importer.current_run
      unzip_imported_file(importer.parser)
      import(importer, only_updates_since_last_import)
      update_current_run_counters(importer)
      schedule(importer) if importer.schedulable?
    end

    def import(importer, only_updates_since_last_import)
      importer.only_updates = only_updates_since_last_import || false
      return unless importer.valid_import?

      importer.import_collections
      importer.import_works
      importer.import_file_sets
    end

    def unzip_imported_file(parser)
      return unless parser.file? && parser.zip?

      parser.unzip(parser.parser_fields['import_file_path'])
    end

    def update_current_run_counters(importer)
      importer.current_run.total_work_entries = importer.limit || importer.parser.works_total
      importer.current_run.total_collection_entries = importer.parser.collections_total
      importer.current_run.total_file_set_entries = importer.parser.file_sets_total
      importer.current_run.save!
    end

    def schedule(importer)
      ImporterJob.set(wait_until: importer.next_import_at).perform_later(importer.id, true)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bulkrax-2.3.0 app/jobs/bulkrax/importer_job.rb
bulkrax-2.2.4 app/jobs/bulkrax/importer_job.rb
bulkrax-2.2.3 app/jobs/bulkrax/importer_job.rb
bulkrax-2.2.2 app/jobs/bulkrax/importer_job.rb
bulkrax-2.2.1 app/jobs/bulkrax/importer_job.rb
bulkrax-2.2.0 app/jobs/bulkrax/importer_job.rb
bulkrax-2.1.1 app/jobs/bulkrax/importer_job.rb
bulkrax-2.1.0 app/jobs/bulkrax/importer_job.rb