[CalendarServer-changes] [10917] CalendarServer/trunk/calendarserver/push
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 13 18:24:12 PDT 2013
Revision: 10917
http://trac.calendarserver.org//changeset/10917
Author: sagen at apple.com
Date: 2013-03-13 18:24:12 -0700 (Wed, 13 Mar 2013)
Log Message:
-----------
Pass WorkItem transactions down through push distributor instead of having APNS create another transaction to look up subscriptions
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/push/amppush.py
CalendarServer/trunk/calendarserver/push/applepush.py
CalendarServer/trunk/calendarserver/push/notifier.py
CalendarServer/trunk/calendarserver/push/test/test_amppush.py
CalendarServer/trunk/calendarserver/push/test/test_applepush.py
CalendarServer/trunk/calendarserver/push/test/test_notifier.py
Modified: CalendarServer/trunk/calendarserver/push/amppush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/amppush.py 2013-03-14 00:06:03 UTC (rev 10916)
+++ CalendarServer/trunk/calendarserver/push/amppush.py 2013-03-14 01:24:12 UTC (rev 10917)
@@ -71,7 +71,7 @@
controlSocket.addFactory(PUSH_ROUTE, AMPPushForwardingFactory(self))
@inlineCallbacks
- def enqueue(self, id, dataChangedTimestamp=None):
+ def enqueue(self, transaction, id, dataChangedTimestamp=None):
if dataChangedTimestamp is None:
dataChangedTimestamp = int(time.time())
for protocol in self.protocols:
@@ -92,7 +92,7 @@
def enqueueFromWorker(self, id, dataChangedTimestamp=None):
if dataChangedTimestamp is None:
dataChangedTimestamp = int(time.time())
- self.master.enqueue(id, dataChangedTimestamp=dataChangedTimestamp)
+ self.master.enqueue(None, id, dataChangedTimestamp=dataChangedTimestamp)
return {"status" : "OK"}
@@ -145,7 +145,7 @@
self.log_debug("Removed subscriber")
self.subscribers.remove(p)
- def enqueue(self, pushKey, dataChangedTimestamp=None):
+ def enqueue(self, transaction, pushKey, dataChangedTimestamp=None):
"""
Sends an AMP push notification to any clients subscribing to this pushKey.
Modified: CalendarServer/trunk/calendarserver/push/applepush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/applepush.py 2013-03-14 00:06:03 UTC (rev 10916)
+++ CalendarServer/trunk/calendarserver/push/applepush.py 2013-03-14 01:24:12 UTC (rev 10917)
@@ -176,7 +176,7 @@
@inlineCallbacks
- def enqueue(self, pushKey, dataChangedTimestamp=None):
+ def enqueue(self, transaction, pushKey, dataChangedTimestamp=None):
"""
Sends an Apple Push Notification to any device token subscribed to
this pushKey.
@@ -207,9 +207,7 @@
if provider is not None:
# Look up subscriptions for this key
- txn = self.store.newTransaction()
- subscriptions = (yield txn.apnSubscriptionsByKey(pushKey))
- yield txn.commit()
+ subscriptions = (yield transaction.apnSubscriptionsByKey(pushKey))
numSubscriptions = len(subscriptions)
if numSubscriptions > 0:
Modified: CalendarServer/trunk/calendarserver/push/notifier.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/notifier.py 2013-03-14 00:06:03 UTC (rev 10916)
+++ CalendarServer/trunk/calendarserver/push/notifier.py 2013-03-14 01:24:12 UTC (rev 10917)
@@ -44,7 +44,7 @@
pushDistributor = self.transaction._pushDistributor
if pushDistributor is not None:
- yield pushDistributor.enqueue(self.pushID)
+ yield pushDistributor.enqueue(self.transaction, self.pushID)
@@ -204,12 +204,15 @@
self.observers = observers
@inlineCallbacks
- def enqueue(self, pushKey):
+ def enqueue(self, transaction, pushKey):
"""
Pass along enqueued pushKey to any observers
+ @param transaction: a transaction to use, if needed
+ @type transaction: L{CommonStoreTransaction}
+
@param pushKey: the push key to distribute to the observers
@type pushKey: C{str}
"""
for observer in self.observers:
- yield observer.enqueue(pushKey)
+ yield observer.enqueue(transaction, pushKey)
Modified: CalendarServer/trunk/calendarserver/push/test/test_amppush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/test/test_amppush.py 2013-03-14 00:06:03 UTC (rev 10916)
+++ CalendarServer/trunk/calendarserver/push/test/test_amppush.py 2013-03-14 01:24:12 UTC (rev 10917)
@@ -57,7 +57,7 @@
self.assertTrue(client3.subscribedToID("/CalDAV/localhost/user03/"))
dataChangedTimestamp = 1354815999
- service.enqueue("/CalDAV/localhost/user01/", dataChangedTimestamp=dataChangedTimestamp)
+ service.enqueue(None, "/CalDAV/localhost/user01/", dataChangedTimestamp=dataChangedTimestamp)
self.assertEquals(len(client1.history), 0)
self.assertEquals(len(client2.history), 0)
self.assertEquals(len(client3.history), 0)
@@ -74,7 +74,7 @@
client1.reset()
client2.reset()
client2.unsubscribe("token2", "/CalDAV/localhost/user01/")
- service.enqueue("/CalDAV/localhost/user01/", dataChangedTimestamp=dataChangedTimestamp)
+ service.enqueue(None, "/CalDAV/localhost/user01/", dataChangedTimestamp=dataChangedTimestamp)
self.assertEquals(len(client1.history), 0)
clock.advance(1)
self.assertEquals(client1.history, [(NotificationForID, {'id': '/CalDAV/localhost/user01/', 'dataChangedTimestamp' : 1354815999})])
@@ -87,7 +87,7 @@
client1.reset()
client2.reset()
client2.subscribe("token2", "/CalDAV/localhost/user01/")
- service.enqueue("/CalDAV/localhost/user01/", dataChangedTimestamp=dataChangedTimestamp)
+ service.enqueue(None, "/CalDAV/localhost/user01/", dataChangedTimestamp=dataChangedTimestamp)
self.assertEquals(client1.history, [(NotificationForID, {'id': '/CalDAV/localhost/user01/', 'dataChangedTimestamp' : 1354815999})])
self.assertEquals(client2.history, [(NotificationForID, {'id': '/CalDAV/localhost/user01/', 'dataChangedTimestamp' : 1354815999})])
Modified: CalendarServer/trunk/calendarserver/push/test/test_applepush.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/test/test_applepush.py 2013-03-14 00:06:03 UTC (rev 10916)
+++ CalendarServer/trunk/calendarserver/push/test/test_applepush.py 2013-03-14 01:24:12 UTC (rev 10917)
@@ -125,8 +125,10 @@
# Notification arrives from calendar server
dataChangedTimestamp = 1354815999
- yield service.enqueue("/CalDAV/calendars.example.com/user01/calendar/",
+ txn = self.store.newTransaction()
+ yield service.enqueue(txn, "/CalDAV/calendars.example.com/user01/calendar/",
dataChangedTimestamp=dataChangedTimestamp)
+ yield txn.commit()
# The notifications should be in the queue
self.assertTrue(((token, key1), dataChangedTimestamp) in service.providers["CalDAV"].queue)
@@ -165,7 +167,9 @@
# Reset sent data
providerConnector.transport.data = None
# Send notification while service is connected
- yield service.enqueue("/CalDAV/calendars.example.com/user01/calendar/")
+ txn = self.store.newTransaction()
+ yield service.enqueue(txn, "/CalDAV/calendars.example.com/user01/calendar/")
+ yield txn.commit()
clock.advance(1) # so that first push is sent
self.assertEquals(len(providerConnector.transport.data), 183)
# Reset sent data
Modified: CalendarServer/trunk/calendarserver/push/test/test_notifier.py
===================================================================
--- CalendarServer/trunk/calendarserver/push/test/test_notifier.py 2013-03-14 00:06:03 UTC (rev 10916)
+++ CalendarServer/trunk/calendarserver/push/test/test_notifier.py 2013-03-14 01:24:12 UTC (rev 10917)
@@ -30,7 +30,7 @@
def reset(self):
self.history = []
- def enqueue(self, id):
+ def enqueue(self, transaction, id):
self.history.append(id)
return(succeed(None))
@@ -40,7 +40,7 @@
def test_enqueue(self):
stub = StubService()
dist = PushDistributor([stub])
- yield dist.enqueue("testing")
+ yield dist.enqueue(None, "testing")
self.assertEquals(stub.history, ["testing"])
def test_getPubSubAPSConfiguration(self):
@@ -82,7 +82,7 @@
def reset(self):
self.history = []
- def enqueue(self, pushID):
+ def enqueue(self, transaction, pushID):
self.history.append(pushID)
class PushNotificationWorkTests(TestCase):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130313/19e6dc0b/attachment-0001.html>
More information about the calendarserver-changes
mailing list