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