Browse Source

try/catch in case of notification error

root 10 years ago
parent
commit
e0c4091fcb
1 changed files with 13 additions and 9 deletions
  1. 13 9
      tracim/tracim/lib/notifications.py

+ 13 - 9
tracim/tracim/lib/notifications.py View File

@@ -53,15 +53,18 @@ class Notifier(object):
53 53
         # INFO - D.A. - 2014-11-05 - Emails are sent through asynchronous jobs. For that reason, we do not
54 54
         # give SQLAlchemy objects but ids only (SQLA objects are related to a given thread/session)
55 55
         #
56
-        if global_config.EMAIL_NOTIFICATION_PROCESSING_MODE.lower()==global_config.CST.ASYNC.lower():
57
-            logger.info(self, 'Sending email in ASYNC mode')
58
-            # TODO - D.A - 2014-11-06
59
-            # This feature must be implemented in order to be able to scale to large communities
60
-            raise NotImplementedError('Sending emails through ASYNC mode is not working yet')
61
-            asyncjob_perform(EmailNotifier(self._smtp_config, global_config).notify_content_update, self._user.user_id, content.content_id)
62
-        else:
63
-            logger.info(self, 'Sending email in SYNC mode')
64
-            EmailNotifier(self._smtp_config, global_config).notify_content_update(self._user.user_id, content.content_id)
56
+        try:
57
+            if global_config.EMAIL_NOTIFICATION_PROCESSING_MODE.lower()==global_config.CST.ASYNC.lower():
58
+                logger.info(self, 'Sending email in ASYNC mode')
59
+                # TODO - D.A - 2014-11-06
60
+                # This feature must be implemented in order to be able to scale to large communities
61
+                raise NotImplementedError('Sending emails through ASYNC mode is not working yet')
62
+                asyncjob_perform(EmailNotifier(self._smtp_config, global_config).notify_content_update, self._user.user_id, content.content_id)
63
+            else:
64
+                logger.info(self, 'Sending email in SYNC mode')
65
+                EmailNotifier(self._smtp_config, global_config).notify_content_update(self._user.user_id, content.content_id)
66
+        except Exception as e:
67
+            logger.error(self, 'Exception catched during email notification: {}'.format(e.__str__()))
65 68
 
66 69
 class EST(object):
67 70
     """
@@ -119,6 +122,7 @@ class EmailNotifier(object):
119 122
             logger.info(self, 'Skipping notification as nobody subscribed to in workspace {}'.format(content.workspace.label))
120 123
             return
121 124
 
125
+
122 126
         logger.info(self, 'Sending asynchronous emails to {} user(s)'.format(len(notifiable_roles)))
123 127
         # INFO - D.A. - 2014-11-06
124 128
         # The following email sender will send emails in the async task queue