Skip to content

Commit

Permalink
Merge pull request #358 from DNO-inc/improve_auth_logs
Browse files Browse the repository at this point in the history
improved logging for email sending loop
  • Loading branch information
m-o-d-e-r authored Jun 5, 2024
2 parents 0e73ef1 + 8f01612 commit 7de2e97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions burrito/apps/notifications/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def email_loop():
raw_data = message.get("data")

if raw_data and isinstance(raw_data, (str, bytes)):
get_logger().info(f"Found such data in the chanel: {raw_data}")
try:
data = orjson.loads(raw_data)
except UnboundLocalError as exc:
Expand Down
10 changes: 8 additions & 2 deletions burrito/utils/email_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import orjson
import smtplib
from email.message import EmailMessage
import traceback

from burrito.utils.config_reader import get_config
from burrito.utils.redis_utils import get_redis_connector
Expand Down Expand Up @@ -46,14 +47,18 @@ def send_email(receivers: list[int], subject: str, content: str) -> None:

# if current_user is not exist
if current_user is None:
get_logger().warning(f"Unexistent user ID ({id_})")
continue
# skip user if email is empty
if not current_user.email:
get_logger().warning(f"Empty email for user ({current_user.user_id})")
continue

receivers_email.append(current_user.email)

if not receivers_email:
get_logger().warning("No email recipients provided")
get_logger().info(f"Receivers IDs list: {receivers}")
return

sender = get_config().BURRITO_EMAIL_LOGIN
Expand All @@ -76,8 +81,9 @@ def send_email(receivers: list[int], subject: str, content: str) -> None:

get_logger().info(f"Email successfully sent to {receivers_email}")

except Exception as exc:
get_logger().warning(f"{exc} Failed to send email to {receivers_email}")
except Exception:
traceback.print_exc()
get_logger().warning(f"Failed to send email to {receivers_email}")


# TODO: delete this function after public tests
Expand Down

0 comments on commit 7de2e97

Please sign in to comment.