Avoid sending mails twice via concurrent background processes.
This commit is contained in:
parent
fe632abf2c
commit
877a55a614
1 changed files with 4 additions and 1 deletions
|
@ -64,6 +64,9 @@ class Message < ActiveRecord::Base
|
|||
# Sends all pending messages that are to be send as emails.
|
||||
def self.send_emails
|
||||
messages = Message.pending
|
||||
# Set all messages not pending, to avoid sending mails twice with different background processes
|
||||
messages.each { |m| m.update_attribute(:email_state, 2) }
|
||||
|
||||
for message in messages
|
||||
for recipient in message.recipients
|
||||
if recipient.settings['messages.sendAsEmail'] == "1" && !recipient.email.blank?
|
||||
|
@ -74,7 +77,7 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
message.update_attribute(:email_state, 1)
|
||||
message.update_attribute(:email_state, 1) # Set email state to 'sent'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue