Use a writing role for some sidekiq worker reads

This commit is contained in:
Fosco Marotto 2021-02-18 15:02:16 -05:00
parent de7d71e0ee
commit 4696307cc9
2 changed files with 8 additions and 4 deletions

View File

@ -4,6 +4,8 @@ class BootstrapTimelineWorker
include Sidekiq::Worker
def perform(account_id)
BootstrapTimelineService.new.call(Account.find(account_id))
ActiveRecord::Base.connected_to(role: :writing) do
BootstrapTimelineService.new.call(Account.find(account_id))
end
end
end

View File

@ -8,10 +8,12 @@ class LocalNotificationWorker
def perform(receiver_account_id, activity_id = nil, activity_class_name = nil)
return true if activity_id.nil? or activity_class_name.nil?
receiver = Account.find(receiver_account_id)
activity = activity_class_name.constantize.find(activity_id)
ActiveRecord::Base.connected_to(role: :writing) do
receiver = Account.find(receiver_account_id)
activity = activity_class_name.constantize.find(activity_id)
NotifyService.new.call(receiver, activity)
NotifyService.new.call(receiver, activity)
end
rescue ActiveRecord::RecordNotFound
true
end