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.



9
10
11
# File 'app/models/spotlight/reindex_progress.rb', line 9

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.



5
6
7
# File 'app/models/spotlight/reindex_progress.rb', line 5

def current_log_entry
  @current_log_entry
end

Instance Method Details

#as_jsonObject



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

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



35
36
37
# File 'app/models/spotlight/reindex_progress.rb', line 35

def completed
  current_log_entry.items_reindexed_count
end

#errored?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/spotlight/reindex_progress.rb', line 39

def errored?
  current_log_entry.failed?
end

#finished?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/spotlight/reindex_progress.rb', line 23

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

#finished_atObject



27
28
29
# File 'app/models/spotlight/reindex_progress.rb', line 27

def finished_at
  current_log_entry.end_time
end

#recently_in_progress?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'app/models/spotlight/reindex_progress.rb', line 13

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



19
20
21
# File 'app/models/spotlight/reindex_progress.rb', line 19

def started_at
  current_log_entry.start_time
end

#totalObject



31
32
33
# File 'app/models/spotlight/reindex_progress.rb', line 31

def total
  current_log_entry.items_reindexed_estimate
end