Add retries to sending emails
We have occasional release announcement job failures due to network issues or other SMTP errors sending the announcement. Most of these appear to be temporary failures that would be resolved with another attempt. This patch adds exponential backoff retries to the sending process to try to get around these failures. Change-Id: I70bb470639385caecee7ccfc0e449449bfc9b871 Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
parent
d2e83aecb7
commit
c5545ee077
|
@ -22,6 +22,8 @@ import argparse
|
|||
import email
|
||||
import smtplib
|
||||
|
||||
import tenacity
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -47,9 +49,14 @@ def main():
|
|||
msg = email.message_from_file(f)
|
||||
|
||||
tolist = [address.strip() for address in msg['to'].split(",")]
|
||||
send_email(server, msg, tolist, user=user, pw=pw, debug=args.verbose)
|
||||
|
||||
server = smtplib.SMTP(server)
|
||||
if args.verbose:
|
||||
|
||||
@tenacity.retry(wait=tenacity.wait_exponential,
|
||||
stop=tenacity.stop_after_attempt(4))
|
||||
def send_email(smtp_server, msg, tolist, user=None, pw=None, debug=False):
|
||||
server = smtplib.SMTP(smtp_server)
|
||||
if debug:
|
||||
server.set_debuglevel(True)
|
||||
try:
|
||||
if pw:
|
||||
|
|
|
@ -19,6 +19,7 @@ mwclient==0.8.1
|
|||
jsonschema>=2.6.0
|
||||
twine>=1.13.0
|
||||
ruamel.yaml>=0.15
|
||||
tenacity>=6.1.0
|
||||
|
||||
# For release notes generation.
|
||||
Jinja2>=2.6 # BSD License (3 clause)
|
||||
|
|
Loading…
Reference in New Issue