Skip to content
Snippets Groups Projects
Commit 79c32878 authored by Bo-Chun Chen's avatar Bo-Chun Chen
Browse files

Send errmsg if error occur

parent 7c5ff0d1
No related branches found
No related tags found
4 merge requests!147Merge previous default branch feat-cod-rmq into main,!85kill nginx process running under user from login node,!78Feat cod rmq,!62Feat notify user errmsg
...@@ -27,6 +27,7 @@ def notify_user(ch, method, properties, body): ...@@ -27,6 +27,7 @@ def notify_user(ch, method, properties, body):
user_email = msg['email'] user_email = msg['email']
msg['task'] = task msg['task'] = task
msg['success'] = False msg['success'] = False
errmsg = ""
try: try:
...@@ -34,6 +35,7 @@ def notify_user(ch, method, properties, body): ...@@ -34,6 +35,7 @@ def notify_user(ch, method, properties, body):
record = table.find_one(username=username) record = table.find_one(username=username)
if record['sent'] is not None: if record['sent'] is not None:
errmsg = 'Updating database counter'
# Update counter # Update counter
count = record['count'] count = record['count']
if args.dry_run: if args.dry_run:
...@@ -58,11 +60,13 @@ def notify_user(ch, method, properties, body): ...@@ -58,11 +60,13 @@ def notify_user(ch, method, properties, body):
logger.info(f"table.update({{'username': {username}, 'count': 1, 'sent_at': datetime.now()}}, ['username'])") logger.info(f"table.update({{'username': {username}, 'count': 1, 'sent_at': datetime.now()}}, ['username'])")
else: else:
errmsg = 'Sending email to user'
smtp = smtplib.SMTP(mail_cfg.Server) smtp = smtplib.SMTP(mail_cfg.Server)
smtp.sendmail(mail_cfg.Sender, receivers, message) smtp.sendmail(mail_cfg.Sender, receivers, message)
logger.debug(f'Email sent to: {user_email}') logger.debug(f'Email sent to: {user_email}')
errmsg = 'Updating database email sent time'
table.update({ table.update({
'username': username, 'username': username,
'count': 1, 'count': 1,
...@@ -74,6 +78,7 @@ def notify_user(ch, method, properties, body): ...@@ -74,6 +78,7 @@ def notify_user(ch, method, properties, body):
msg['success'] = True msg['success'] = True
except Exception as exception: except Exception as exception:
logger.error('', exc_info=True) logger.error('', exc_info=True)
msg['errmsg'] = errmsg if errmsg else 'Unexpected error'
# Send confirm message # Send confirm message
rc_rmq.publish_msg({ rc_rmq.publish_msg({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment