Updated signal_handler subscription, specific exceptions & logging stream
Some checks failed
buildbot/travis_bionic Build done.

This commit is contained in:
kuldeep.k@cisinlabs.com 2022-02-17 22:31:39 +05:30
parent c3830ce249
commit 1d69818718

View File

@ -14,7 +14,7 @@ from email.mime.text import MIMEText
import cherrypy import cherrypy
import logging import logging
logging.basicConfig(filename='app.log', filemode='w', logging.basicConfig(stream=sys.stdout,
format='%(name)s - %(levelname)s - %(message)s') format='%(name)s - %(levelname)s - %(message)s')
@ -49,7 +49,7 @@ class SMTPWebhookApp:
try: try:
client = smtplib.SMTP(host=SMTP_SERVER_HOST, port=SMTP_SERVER_PORT) client = smtplib.SMTP(host=SMTP_SERVER_HOST, port=SMTP_SERVER_PORT)
except Exception as e: except (smtplib.SMTPConnectionError, TimeoutError) as e:
time.sleep(0.2) time.sleep(0.2)
logging.error("To: {}, error: {}".format(TO_MAIL, e)) logging.error("To: {}, error: {}".format(TO_MAIL, e))
return {"status": 400, "message": "SMTP client error: {}.".format( return {"status": 400, "message": "SMTP client error: {}.".format(
@ -109,6 +109,10 @@ if __name__ == "__main__":
cherrypy.tree.mount(ROOT, config={}) cherrypy.tree.mount(ROOT, config={})
if hasattr(ENGINE, "signal_handler"):
ENGINE.signal_handler.subscribe()
if hasattr(ENGINE, "console_control_handler"):
ENGINE.console_control_handler.subscribe()
try: try:
ENGINE.start() ENGINE.start()
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except