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