From b294478d5bd925e628b6cedd279c808768ad9a89 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 30 Jul 2019 16:27:39 -0700 Subject: [PATCH] Added index_name to jobs --- lib/searchkick/index.rb | 7 +++++-- lib/searchkick/model.rb | 5 +++-- lib/searchkick/process_batch_job.rb | 4 ++-- lib/searchkick/process_queue_job.rb | 13 ++++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/searchkick/index.rb b/lib/searchkick/index.rb index c6f5721..88d22dc 100644 --- a/lib/searchkick/index.rb +++ b/lib/searchkick/index.rb @@ -259,6 +259,10 @@ module Searchkick @bulk_indexer ||= BulkIndexer.new(self) end + def import_before_promotion(index, relation, **import_options) + index.import_scope(relation, **import_options) + end + # https://gist.github.com/jarosan/3124884 # http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/ def reindex_scope(relation, import: true, resume: false, retain: false, async: false, refresh_interval: nil, scope: nil) @@ -284,8 +288,7 @@ module Searchkick # check if alias exists alias_exists = alias_exists? if alias_exists - # import before promotion - index.import_scope(relation, **import_options) if import + import_before_promotion(index, relation, **import_options) if import # get existing indices to remove unless async diff --git a/lib/searchkick/model.rb b/lib/searchkick/model.rb index 17ab288..00d2112 100644 --- a/lib/searchkick/model.rb +++ b/lib/searchkick/model.rb @@ -15,6 +15,7 @@ module Searchkick Searchkick.models << self options[:_type] ||= -> { searchkick_index.klass_document_type(self, true) } + options[:class_name] = name callbacks = options.key?(:callbacks) ? options[:callbacks] : :inline unless [:inline, true, false, :async, :queue].include?(callbacks) @@ -44,8 +45,8 @@ module Searchkick end alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name - def searchkick_index - index = class_variable_get(:@@searchkick_index) + def searchkick_index(name: nil) + index = name || class_variable_get(:@@searchkick_index) index = index.call if index.respond_to?(:call) index_cache = class_variable_get(:@@searchkick_index_cache) index_cache[index] ||= Searchkick::Index.new(index, searchkick_options) diff --git a/lib/searchkick/process_batch_job.rb b/lib/searchkick/process_batch_job.rb index 04953b6..b92294b 100644 --- a/lib/searchkick/process_batch_job.rb +++ b/lib/searchkick/process_batch_job.rb @@ -2,7 +2,7 @@ module Searchkick class ProcessBatchJob < ActiveJob::Base queue_as { Searchkick.queue_name } - def perform(class_name:, record_ids:) + def perform(class_name:, record_ids:, index_name: nil) # separate routing from id routing = Hash[record_ids.map { |r| r.split(/(?