2022-05-19 00:29:14 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Scheduler::IndexingScheduler
|
|
|
|
include Sidekiq::Worker
|
|
|
|
include Redisable
|
|
|
|
|
|
|
|
sidekiq_options retry: 0
|
|
|
|
|
2023-03-31 15:38:47 +03:00
|
|
|
IMPORT_BATCH_SIZE = 1000
|
|
|
|
SCAN_BATCH_SIZE = 10 * IMPORT_BATCH_SIZE
|
|
|
|
|
2022-05-19 00:29:14 +03:00
|
|
|
def perform
|
2022-11-05 23:31:52 +02:00
|
|
|
return unless Chewy.enabled?
|
|
|
|
|
2022-05-19 00:29:14 +03:00
|
|
|
indexes.each do |type|
|
|
|
|
with_redis do |redis|
|
2023-04-01 09:28:35 +03:00
|
|
|
redis.sscan_each("chewy:queue:#{type.name}", count: SCAN_BATCH_SIZE).each_slice(IMPORT_BATCH_SIZE) do |ids|
|
|
|
|
type.import!(ids)
|
|
|
|
redis.pipelined do |pipeline|
|
|
|
|
pipeline.srem("chewy:queue:#{type.name}", ids)
|
2023-03-31 15:38:47 +03:00
|
|
|
end
|
2022-05-19 00:29:14 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def indexes
|
|
|
|
[AccountsIndex, TagsIndex, StatusesIndex]
|
|
|
|
end
|
|
|
|
end
|