Add mutex around incoming email processing

This commit is contained in:
Régis Hanol 2017-05-18 01:09:51 +02:00
parent 2a5a01af2e
commit 80435cf2af
1 changed files with 10 additions and 6 deletions

View File

@ -39,12 +39,16 @@ module Email
def process! def process!
return if is_blacklisted? return if is_blacklisted?
@from_email, @from_display_name = parse_from_field(@mail) DistributedMutex.synchronize(@message_id) do
@incoming_email = find_or_create_incoming_email begin
process_internal @from_email, @from_display_name = parse_from_field(@mail)
rescue => e @incoming_email = find_or_create_incoming_email
@incoming_email.update_columns(error: e.to_s) if @incoming_email process_internal
raise rescue => e
@incoming_email.update_columns(error: e.to_s) if @incoming_email
raise
end
end
end end
def is_blacklisted? def is_blacklisted?