You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/05/30 18:42:05 UTC

[20/24] git commit: [#4994] Fixed race condition when posting notifications

[#4994] Fixed race condition when posting notifications

If the thread that posts the notification takes a while to flush the
session (most easily seen on repo refreshes), then the Task can get
started before the new Notification instance is saved to mongo

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/956b6c5f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/956b6c5f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/956b6c5f

Branch: refs/heads/cj/6218
Commit: 956b6c5f19c92b59d61298c8f11f0166b807243b
Parents: f3923bf
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Wed May 29 22:58:40 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Wed May 29 23:10:23 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/notification.py |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/956b6c5f/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index ebc0eef..f5c9c6b 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -106,6 +106,8 @@ class Notification(MappedClass):
         import allura.tasks.notification_tasks
         n = cls._make_notification(artifact, topic, **kw)
         if n:
+            # make sure notification is flushed in time for task to process it
+            session(n).flush(n)
             allura.tasks.notification_tasks.notify.post(
                 n._id, artifact.index_id(), topic)
         return n
@@ -532,7 +534,10 @@ class Mailbox(MappedClass):
         '''
         notifications = Notification.query.find(dict(_id={'$in':self.queue}))
         notifications = notifications.all()
-        log.debug('Firing mailbox %s notifications [%s], found [%s]', str(self._id), ', '.join(self.queue), ', '.join([n._id for n in notifications]))
+        if len(notifications) != len(self.queue):
+            log.error('Mailbox queue error: Mailbox %s queued [%s], found [%s]', str(self._id), ', '.join(self.queue), ', '.join([n._id for n in notifications]))
+        else:
+            log.debug('Firing mailbox %s notifications [%s], found [%s]', str(self._id), ', '.join(self.queue), ', '.join([n._id for n in notifications]))
         if self.type == 'direct':
             ngroups = defaultdict(list)
             for n in notifications: