Class: GoodJob::ElasticsearchOnFinishReindex

Inherits:
HasUtils::GoodJob::BaseWorker
  • Object
show all
Includes:
HasUtils::GoodJob::UniqueJob
Defined in:
app/workers/good_job/elasticsearch_on_finish_reindex.rb

Instance Method Summary collapse

Instance Method Details

#perform(index_class_name, index_name, start_time) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/workers/good_job/elasticsearch_on_finish_reindex.rb', line 10

def perform(index_class_name, index_name, start_time)
  index_class = index_class_name.constantize
  is_keyword_index = index_name.include?("keyword")
  index_class.promote(index_name)

  queue = is_keyword_index ? index_class.keyword_reindex_queue : index_class.reindex_queue

  # Index all records updated during the reindex
  index_class.active_record.where("updated_at + INTERVAL '1 second' >= ?", start_time).find_each do |record|
    queue.push(record.id.to_s)
  end

  GoodJob::ElasticsearchProcessQueue.perform_later(index_class.name, index_name)
  index_class.update_settings(index_name, index: { refresh_interval: "1s" })
end