Skip to content

Commit

Permalink
Merge pull request #21 from bepatient-fr/6659_attempt_to_fix_email_se…
Browse files Browse the repository at this point in the history
…nd_concurrency

(#MOBI-6659) Attempt to fix email send gevent concurrency
  • Loading branch information
M3te0r authored Jun 16, 2022
2 parents 07a0c89 + 8b8a00b commit 522fd0b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ikaaro/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# Import from the Standard Library
#from cProfile import runctx
from email.parser import BytesHeaderParser
import fcntl
from json import loads
from io import BytesIO
from datetime import timedelta
Expand Down Expand Up @@ -788,7 +789,10 @@ def get_names():
smtp = SMTP(smtp_host)
except Exception as e:
self.smtp_log_error()
spool.move(name, 'failed/%s' % name)
try:
spool.move(name, 'failed/%s' % name)
except FileNotFoundError:
continue
return 60 if get_names() else False
log_ikaaro.info("CONNECTED to {}".format(smtp_host))

Expand All @@ -798,7 +802,17 @@ def get_names():

# 3. Send message
try:
message = spool.open(name).read()
try:
message_file = spool.open(name)
except FileNotFoundError:
continue
try:
fcntl.flock(message_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
except BlockingIOError:
message_file.close()
continue
message = message_file.read()
message_file.close()
headers = BytesHeaderParser().parsebytes(message)
subject = headers['subject']
from_addr = headers['from']
Expand Down

0 comments on commit 522fd0b

Please sign in to comment.