Sha256: f4c2a08557a7a66b9217b10fd2e09c212fd1da9dfc846700c27f630c720f2186

Contents?: true

Size: 1.1 KB

Versions: 12

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Spotlight
  ###
  class AddTagsJob < Spotlight::ApplicationJob
    include Spotlight::JobTracking
    include Spotlight::GatherDocuments
    with_job_tracking(resource: ->(job) { job.arguments.last[:exhibit] })

    # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
    def perform(solr_params:, exhibit:, tags:, **)
      @errors = 0

      each_document(solr_params, exhibit) do |document|
        sidecar = document.sidecar(exhibit)
        all_tags = sidecar.all_tags_list
        all_tags += tags
        exhibit.tag(document.sidecar(exhibit), with: all_tags, on: :tags)
        document.reindex(update_params: {})
        progress&.increment
      rescue StandardError => e
        job_tracker.append_log_entry(type: :error, 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:, message: "#{progress.progress} of #{progress.total} (#{@errors} errors)")
    end
    # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-spotlight-4.7.0 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.6.1 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.6.0 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.5.0 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.4.0 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.3.6 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.3.5 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.3.4 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.3.3 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.3.2 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.3.1 app/jobs/spotlight/add_tags_job.rb
blacklight-spotlight-4.3.0 app/jobs/spotlight/add_tags_job.rb