Class: Spotlight::ReindexProgress
- Inherits:
-
Object
- Object
- Spotlight::ReindexProgress
- Defined in:
- app/models/spotlight/reindex_progress.rb
Overview
ReindexProgress is a class that models the progress of reindexing a list of resources
Instance Method Summary collapse
- #as_json ⇒ Object
- #completed ⇒ Object
- #errored? ⇒ Boolean
- #finished? ⇒ Boolean
- #finished_at ⇒ Object
-
#initialize(resource_list) ⇒ ReindexProgress
constructor
A new instance of ReindexProgress.
- #recently_in_progress? ⇒ Boolean
- #started_at ⇒ Object
- #total ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize(resource_list) ⇒ ReindexProgress
Returns a new instance of ReindexProgress.
5 6 7 8 9 10 11 |
# File 'app/models/spotlight/reindex_progress.rb', line 5 def initialize(resource_list) @resources = if resource_list.present? resource_list.order('updated_at') else Spotlight::Resource.none end end |
Instance Method Details
#as_json ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/spotlight/reindex_progress.rb', line 52 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, errored: errored? } end |
#completed ⇒ Object
44 45 46 |
# File 'app/models/spotlight/reindex_progress.rb', line 44 def completed @completed ||= resources.map(&:last_indexed_count).compact.sum end |
#errored? ⇒ Boolean
48 49 50 |
# File 'app/models/spotlight/reindex_progress.rb', line 48 def errored? resources.any?(&:errored?) end |
#finished? ⇒ Boolean
31 32 33 |
# File 'app/models/spotlight/reindex_progress.rb', line 31 def finished? completed_resources.present? && !any_waiting? end |
#finished_at ⇒ Object
35 36 37 38 |
# File 'app/models/spotlight/reindex_progress.rb', line 35 def finished_at return unless finished? @finished ||= completed_resources.max_by(&:last_indexed_finished).last_indexed_finished end |
#recently_in_progress? ⇒ Boolean
13 14 15 |
# File 'app/models/spotlight/reindex_progress.rb', line 13 def recently_in_progress? any_waiting? || (!!finished_at && finished_at > Spotlight::Engine.config.reindex_progress_window.minutes.ago) end |
#started_at ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/models/spotlight/reindex_progress.rb', line 17 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 end |
#total ⇒ Object
40 41 42 |
# File 'app/models/spotlight/reindex_progress.rb', line 40 def total @total ||= resources.map(&:last_indexed_estimate).compact.sum end |
#updated_at ⇒ Object
27 28 29 |
# File 'app/models/spotlight/reindex_progress.rb', line 27 def updated_at @updated ||= resources.maximum(:updated_at) || started_at end |