This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2022-05-18 14:29:14 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Scheduler::IndexingScheduler
|
|
|
|
include Sidekiq::Worker
|
|
|
|
include Redisable
|
|
|
|
|
|
|
|
sidekiq_options retry: 0
|
|
|
|
|
2023-03-31 05:38:47 -07:00
|
|
|
IMPORT_BATCH_SIZE = 1000
|
|
|
|
SCAN_BATCH_SIZE = 10 * IMPORT_BATCH_SIZE
|
|
|
|
|
2022-05-18 14:29:14 -07:00
|
|
|
def perform
|
2022-11-05 14:31:52 -07:00
|
|
|
return unless Chewy.enabled?
|
|
|
|
|
2022-05-18 14:29:14 -07:00
|
|
|
indexes.each do |type|
|
|
|
|
with_redis do |redis|
|
2023-03-31 05:38:47 -07:00
|
|
|
redis.sscan_each("chewy:queue:#{type.name}", count: SCAN_BATCH_SIZE) do |ids|
|
|
|
|
redis.pipelined do
|
|
|
|
ids.each_slice(IMPORT_BATCH_SIZE) do |slice_ids|
|
|
|
|
type.import!(slice_ids)
|
|
|
|
redis.srem("chewy:queue:#{type.name}", slice_ids)
|
|
|
|
end
|
|
|
|
end
|
2022-05-18 14:29:14 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def indexes
|
|
|
|
[AccountsIndex, TagsIndex, StatusesIndex]
|
|
|
|
end
|
|
|
|
end
|