Commit 0c47d351663b9bf0a4d102137feca2e5fa5a8be3
1 parent
f6f637ff
Exists in
master
and in
16 other branches
Added index_name to ProcessQueueJob
Showing
3 changed files
with
8 additions
and
7 deletions
Show diff stats
lib/searchkick/model.rb
... | ... | @@ -45,8 +45,8 @@ module Searchkick |
45 | 45 | end |
46 | 46 | alias_method Searchkick.search_method_name, :searchkick_search if Searchkick.search_method_name |
47 | 47 | |
48 | - def searchkick_index | |
49 | - index = class_variable_get(:@@searchkick_index) | |
48 | + def searchkick_index(name: nil) | |
49 | + index = name || class_variable_get(:@@searchkick_index) | |
50 | 50 | index = index.call if index.respond_to?(:call) |
51 | 51 | index_cache = class_variable_get(:@@searchkick_index_cache) |
52 | 52 | index_cache[index] ||= Searchkick::Index.new(index, searchkick_options) | ... | ... |
lib/searchkick/process_batch_job.rb
... | ... | @@ -2,7 +2,7 @@ module Searchkick |
2 | 2 | class ProcessBatchJob < ActiveJob::Base |
3 | 3 | queue_as { Searchkick.queue_name } |
4 | 4 | |
5 | - def perform(class_name:, record_ids:) | |
5 | + def perform(class_name:, record_ids:, index_name: nil) | |
6 | 6 | # separate routing from id |
7 | 7 | routing = Hash[record_ids.map { |r| r.split(/(?<!\|)\|(?!\|)/, 2).map { |v| v.gsub("||", "|") } }] |
8 | 8 | record_ids = routing.keys |
... | ... | @@ -26,7 +26,7 @@ module Searchkick |
26 | 26 | end |
27 | 27 | |
28 | 28 | # bulk reindex |
29 | - index = klass.searchkick_index | |
29 | + index = klass.searchkick_index(name: index_name) | |
30 | 30 | Searchkick.callbacks(:bulk) do |
31 | 31 | index.bulk_index(records) if records.any? |
32 | 32 | index.bulk_delete(delete_records) if delete_records.any? | ... | ... |
lib/searchkick/process_queue_job.rb
... | ... | @@ -2,16 +2,17 @@ module Searchkick |
2 | 2 | class ProcessQueueJob < ActiveJob::Base |
3 | 3 | queue_as { Searchkick.queue_name } |
4 | 4 | |
5 | - def perform(class_name:, inline: false) | |
5 | + def perform(class_name:, index_name: nil, inline: false) | |
6 | 6 | model = class_name.constantize |
7 | 7 | limit = model.searchkick_options[:batch_size] || 1000 |
8 | 8 | |
9 | 9 | loop do |
10 | - record_ids = model.searchkick_index.reindex_queue.reserve(limit: limit) | |
10 | + record_ids = model.searchkick_index(name: index_name).reindex_queue.reserve(limit: limit) | |
11 | 11 | if record_ids.any? |
12 | 12 | batch_options = { |
13 | 13 | class_name: class_name, |
14 | - record_ids: record_ids | |
14 | + record_ids: record_ids, | |
15 | + index_name: index_name | |
15 | 16 | } |
16 | 17 | |
17 | 18 | if inline | ... | ... |