Sha256: d5188aaa4f69cccf29c15bb6fff492e629b4910a369b472e9fcacbe42b305462

Contents?: true

Size: 1.34 KB

Versions: 34

Compression:

Stored size: 1.34 KB

Contents

module Spotlight
  ##
  # Reindex the given resources or exhibits
  class ReindexJob < ActiveJob::Base
    queue_as :default

    before_perform do |job|
      job_log_entry = log_entry(job)
      next unless job_log_entry

      items_reindexed_estimate = resource_list(job.arguments.first).sum do |resource|
        resource.document_builder.documents_to_index.size
      end
      job_log_entry.update(items_reindexed_estimate: items_reindexed_estimate)
    end

    around_perform do |job, block|
      job_log_entry = log_entry(job)
      job_log_entry.in_progress! if job_log_entry

      begin
        block.call
      rescue
        job_log_entry.failed! if job_log_entry
        raise
      end

      job_log_entry.succeeded! if job_log_entry
    end

    def perform(exhibit_or_resources, log_entry = nil)
      resource_list(exhibit_or_resources).each do |resource|
        resource.reindex(log_entry)
      end
    end

    private

    def resource_list(exhibit_or_resources)
      if exhibit_or_resources.is_a?(Spotlight::Exhibit)
        exhibit_or_resources.resources.find_each
      elsif exhibit_or_resources.is_a?(Enumerable)
        exhibit_or_resources
      else
        Array(exhibit_or_resources)
      end
    end

    def log_entry(job)
      job.arguments.second if job.arguments.second.is_a?(Spotlight::ReindexingLogEntry)
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.4.0 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.3.3 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.3.2 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.3.1 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.3.0 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.2.1 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.2.0 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.1.0 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.2 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.1 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.0 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.0.rc6 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.0.rc5 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.0.rc4 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.0.rc3 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.0.rc2 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-2.0.0.rc1 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-1.5.1 app/jobs/spotlight/reindex_job.rb
blacklight-spotlight-1.4.1 app/jobs/spotlight/reindex_job.rb