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
Defined Under Namespace
Classes: NullResource
Instance Method Summary collapse
- #as_json ⇒ Object
- #completed ⇒ Object
- #errored? ⇒ Boolean
- #finished ⇒ Object
- #in_progress? ⇒ Boolean
-
#initialize(resource_list) ⇒ ReindexProgress
constructor
A new instance of ReindexProgress.
- #started ⇒ Object
- #total ⇒ 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 else null_resources end end |
Instance Method Details
#as_json ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/spotlight/reindex_progress.rb', line 38 def as_json(*) { in_progress: in_progress?, started: localized_start_time, total: total, completed: completed, updated_at: localized_finish_time, errored: errored? } end |
#completed ⇒ Object
30 31 32 |
# File 'app/models/spotlight/reindex_progress.rb', line 30 def completed @completed ||= completed_resources.map(&:last_indexed_count).sum end |
#errored? ⇒ Boolean
34 35 36 |
# File 'app/models/spotlight/reindex_progress.rb', line 34 def errored? resources.any?(&:errored?) end |
#finished ⇒ Object
22 23 24 |
# File 'app/models/spotlight/reindex_progress.rb', line 22 def finished @finished ||= completed_resources.last.updated_at end |
#in_progress? ⇒ Boolean
13 14 15 16 |
# File 'app/models/spotlight/reindex_progress.rb', line 13 def in_progress? return unless finished any_waiting? || finished > Spotlight::Engine.config.reindex_progress_window.minutes.ago end |
#started ⇒ Object
18 19 20 |
# File 'app/models/spotlight/reindex_progress.rb', line 18 def started @started ||= resources.first.indexed_at end |
#total ⇒ Object
26 27 28 |
# File 'app/models/spotlight/reindex_progress.rb', line 26 def total @total ||= resources.map(&:last_indexed_estimate).sum end |