From 4fbb113de14197de42db33ea67aa5f5e071f0939 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Fri, 24 Aug 2012 18:52:26 -0400 Subject: added logging to the post-related instant alert sender --- askbot/conf/email.py | 4 ++-- askbot/models/__init__.py | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/askbot/conf/email.py b/askbot/conf/email.py index 1b81fa96..c6c1cb1c 100644 --- a/askbot/conf/email.py +++ b/askbot/conf/email.py @@ -66,7 +66,7 @@ settings.register( livesettings.StringValue( EMAIL, 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_Q_ASK', - default='w', + default='i', choices=const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES, description=_('Default notification frequency questions asked by the user'), help_text=_( @@ -94,7 +94,7 @@ settings.register( livesettings.StringValue( EMAIL, 'DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE_Q_SEL', - default='w', + default='i', choices=const.NOTIFICATION_DELIVERY_SCHEDULE_CHOICES, description=_('Default notification frequency questions individually \ selected by the user'), diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index dc499d70..01779655 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -6,6 +6,7 @@ import datetime import hashlib import logging import urllib +import uuid from django.core.urlresolvers import reverse, NoReverseMatch from django.db.models import signals as django_signals from django.template import Context @@ -2989,6 +2990,16 @@ def send_instant_notifications_about_activity_in_post( origin_post, update_activity.activity_type ) + + logger = logging.getLogger() + if logger.getEffectiveLevel() <= logging.DEBUG: + message = 'email alert for %s post id=%d' % (post.post_type, post.id) + log_id = uuid.uuid1() + message += ', logId=%s' % log_id + #logger.debug(message) + else: + log_id = None + #send email for all recipients for user in recipients: @@ -3008,14 +3019,24 @@ def send_instant_notifications_about_activity_in_post( ) headers['Reply-To'] = reply_address - mail.send_mail( - subject_line = subject_line, - body_text = body_text, - recipient_list = [user.email], - related_object = origin_post, - activity_type = const.TYPE_ACTIVITY_EMAIL_UPDATE_SENT, - headers = headers - ) + try: + mail.send_mail( + subject_line=subject_line, + body_text=body_text, + recipient_list=[user.email], + related_object=origin_post, + activity_type=const.TYPE_ACTIVITY_EMAIL_UPDATE_SENT, + headers=headers, + raise_on_failure=True + ) + except askbot_exceptions.EmailNotSent, error: + logger.debug( + 'fail %s, error=%s, logId=%s' % (user.email, error, log_id) + ) + else: + pass + #logger.debug('success %s, logId=%s' % (user.email, log_id)) + def notify_author_of_published_revision( revision = None, was_approved = None, **kwargs -- cgit v1.2.3-1-g7c22