Sha256: fd23ce12ca5e07f6cd5c272ddeed508e9b1bf9e140d00edf79ec0514196340f5

Contents?: true

Size: 1.64 KB

Versions: 12

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module Spotlight
  ##
  # ReindexProgress is a class that models the progress of reindexing a list of resources
  class ReindexProgress
    attr_reader :current_log_entry

    delegate :updated_at, to: :current_log_entry

    def initialize(current_log_entry)
      @current_log_entry = current_log_entry
    end

    def recently_in_progress?
      return true if current_log_entry.in_progress?

      current_log_entry.end_time.present? && (current_log_entry.end_time > Spotlight::Engine.config.reindex_progress_window.minutes.ago)
    end

    def started_at
      current_log_entry.start_time
    end

    def finished?
      current_log_entry.succeeded? || current_log_entry.failed?
    end

    def finished_at
      current_log_entry.end_time
    end

    def total
      current_log_entry.items_reindexed_estimate
    end

    def completed
      current_log_entry.items_reindexed_count
    end

    def errored?
      current_log_entry.failed?
    end

    def as_json(*)
      {
        recently_in_progress: recently_in_progress?,
        started_at: localized_start_time,
        finished_at: localized_finish_time,
        updated_at: localized_updated_time,
        total: total,
        completed: completed,
        finished: finished?,
        errored: errored?
      }
    end

    private

    def localized_start_time
      return unless started_at

      I18n.l(started_at, format: :long)
    end

    def localized_finish_time
      return unless finished_at

      I18n.l(finished_at, format: :long)
    end

    def localized_updated_time
      return unless updated_at

      I18n.l(updated_at, format: :long)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc3 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.rc2 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.rc1 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.10 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.9 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.8 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.7 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.6 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.5 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.4 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.3 app/models/spotlight/reindex_progress.rb
blacklight-spotlight-3.0.0.alpha.2 app/models/spotlight/reindex_progress.rb