Change indexing jobs to use database replica (#26692)

pull/26693/head
Eugen Rochko 2023-08-27 22:38:01 +02:00 committed by GitHub
parent 5694e24bbf
commit e263db276f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -2,15 +2,20 @@
class AddToPublicStatusesIndexWorker
include Sidekiq::Worker
include DatabaseHelper
sidekiq_options queue: 'pull'
def perform(account_id)
account = Account.find(account_id)
with_primary do
@account = Account.find(account_id)
end
return unless account.indexable?
return unless @account.indexable?
account.add_to_public_statuses_index!
with_read_replica do
@account.add_to_public_statuses_index!
end
rescue ActiveRecord::RecordNotFound
true
end

View File

@ -3,6 +3,7 @@
class Scheduler::IndexingScheduler
include Sidekiq::Worker
include Redisable
include DatabaseHelper
sidekiq_options retry: 0, lock: :until_executed, lock_ttl: 1.day.to_i
@ -15,7 +16,10 @@ class Scheduler::IndexingScheduler
indexes.each do |type|
with_redis do |redis|
redis.sscan_each("chewy:queue:#{type.name}", count: SCAN_BATCH_SIZE).each_slice(IMPORT_BATCH_SIZE) do |ids|
type.import!(ids)
with_read_replica do
type.import!(ids)
end
redis.srem("chewy:queue:#{type.name}", ids)
end
end