app/models/spotlight/reindex_progress.rb in blacklight-spotlight-0.31.0 vs app/models/spotlight/reindex_progress.rb in blacklight-spotlight-0.32.0

- old
+ new

@@ -1,54 +1,50 @@ module Spotlight ## # ReindexProgress is a class that models the progress of reindexing a list of resources class ReindexProgress - def initialize(resource_list) - @resources = if resource_list.present? - resource_list.order('updated_at') - else - Spotlight::Resource.none - end + attr_reader :exhibit + + def initialize(exhibit) + @exhibit = exhibit end def recently_in_progress? - any_waiting? || (!!finished_at && finished_at > Spotlight::Engine.config.reindex_progress_window.minutes.ago) + return false if current_log_entry.blank? + 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 - return unless resources.present? - - enqueued_resources = resources.select(&:enqueued_at?) - - return unless enqueued_resources.any? - - @started ||= enqueued_resources.min_by(&:enqueued_at).enqueued_at + current_log_entry.try(:start_time) end def updated_at - @updated ||= resources.maximum(:updated_at) || started_at + current_log_entry.try(:updated_at) end def finished? - completed_resources.present? && !any_waiting? + return false if current_log_entry.blank? + current_log_entry.succeeded? || current_log_entry.failed? end def finished_at - return unless finished? - @finished ||= completed_resources.max_by(&:last_indexed_finished).last_indexed_finished + current_log_entry.try(:end_time) end def total - @total ||= resources.map(&:last_indexed_estimate).compact.sum + current_log_entry.try(:items_reindexed_estimate) end def completed - @completed ||= resources.map(&:last_indexed_count).compact.sum + current_log_entry.try(:items_reindexed_count) end def errored? - resources.any?(&:errored?) + return false if current_log_entry.blank? + current_log_entry.failed? end def as_json(*) { recently_in_progress: recently_in_progress?, @@ -61,14 +57,12 @@ } end private - attr_reader :resources - - def any_waiting? - resources.any?(&:waiting?) + def current_log_entry + exhibit.reindexing_log_entries.where.not(job_status: 'unstarted').first end def localized_start_time return unless started_at I18n.l(started_at, format: :short) @@ -80,12 +74,8 @@ end def localized_updated_time return unless updated_at I18n.l(updated_at, format: :short) - end - - def completed_resources - resources.completed end end end