Class: Spotlight::ReindexProgress

Inherits:
Object
  • Object
show all
Defined in:
app/models/spotlight/reindex_progress.rb

Overview

ReindexProgress is a class that models the progress of reindexing a list of resources

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_log_entry) ⇒ ReindexProgress

Returns a new instance of ReindexProgress.



11
12
13
# File 'app/models/spotlight/reindex_progress.rb', line 11

def initialize(current_log_entry)
  @current_log_entry = current_log_entry
end

Instance Attribute Details

#current_log_entryObject (readonly)

Returns the value of attribute current_log_entry.



7
8
9
# File 'app/models/spotlight/reindex_progress.rb', line 7

def current_log_entry
  @current_log_entry
end

Instance Method Details

#as_jsonObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/spotlight/reindex_progress.rb', line 45

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

#completedObject



37
38
39
# File 'app/models/spotlight/reindex_progress.rb', line 37

def completed
  current_log_entry.items_reindexed_count
end

#errored?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/spotlight/reindex_progress.rb', line 41

def errored?
  current_log_entry.failed?
end

#finished?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/spotlight/reindex_progress.rb', line 25

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

#finished_atObject



29
30
31
# File 'app/models/spotlight/reindex_progress.rb', line 29

def finished_at
  current_log_entry.end_time
end

#recently_in_progress?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'app/models/spotlight/reindex_progress.rb', line 15

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

#started_atObject



21
22
23
# File 'app/models/spotlight/reindex_progress.rb', line 21

def started_at
  current_log_entry.start_time
end

#totalObject



33
34
35
# File 'app/models/spotlight/reindex_progress.rb', line 33

def total
  current_log_entry.items_reindexed_estimate
end