Try to address the concurrency problem
This commit is contained in:
parent
eb8f60192f
commit
3fa1ac101c
@ -104,8 +104,12 @@ class Member < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.regenerate_all_notifications
|
||||
Member.all.each do |member|
|
||||
member.regenerate_notifications
|
||||
ActiveRecord::Base.transaction do
|
||||
ActiveRecord::Base.connection.execute('LOCK members IN ACCESS EXCLUSIVE MODE')
|
||||
|
||||
Member.all.each do |member|
|
||||
member.regenerate_notifications
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -4,8 +4,12 @@ class Notification < ApplicationRecord
|
||||
scope :scheduled_for_today, ->() { where(status: 'scheduled', to_be_sent_on: Date.today) }
|
||||
|
||||
def self.send_scheduled_for_today
|
||||
scheduled_for_today.each do |n|
|
||||
n.deliver!
|
||||
ActiveRecord::Base.transaction do
|
||||
ActiveRecord::Base.connection.execute('LOCK members IN ACCESS EXCLUSIVE MODE')
|
||||
|
||||
scheduled_for_today.each do |n|
|
||||
n.deliver!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user