Class: ElasticsearchReindexScheduler

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/elasticsearch_reindex_scheduler.rb

Instance Method Summary collapse

Instance Method Details

#on_success(_status, options) ⇒ Object



31
32
33
34
# File 'app/workers/elasticsearch_reindex_scheduler.rb', line 31

def on_success(_status, options)
  index_class_name = options["index_class_name"]
  ::Stat.save_to_stats(::Stat.new, index_class_name, "Elasticsearch", "Reindex", index_class_name.constantize.model.table_name, options["start_time"], Process.clock_gettime(Process::CLOCK_MONOTONIC))
end

#perform(index_class_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/workers/elasticsearch_reindex_scheduler.rb', line 7

def perform(index_class_name)
  index_class = index_class_name.constantize

  logger.info "ElasticsearchReindexScheduler #{index_class_name}"

  return self.class.perform_in(1.minute, index_class) unless index_class.indexing_allowed? || !index_class.is_heavy_index

  starting_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  options = { index_class_name: index_class_name, start_time: starting_time }

  reindex_batch = Sidekiq::Batch.new
  reindex_batch.on(:success, self.class, options)
  reindex_batch.description = "Reindex for #{index_class_name} started at #{DateTime.current.iso8601}"
  reindex_batch.jobs do
    index_class.reindex
  end

  ::HasUtils::Env.run_on_environment(::HasUtils::Env::TEST) do
    if Sidekiq::Testing.inline?
      on_success("status", options)
    end
  end
end