[CalendarServer-changes] [11071] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Apr 19 14:29:57 PDT 2013


Revision: 11071
          http://trac.calendarserver.org//changeset/11071
Author:   sagen at apple.com
Date:     2013-04-19 14:29:57 -0700 (Fri, 19 Apr 2013)
Log Message:
-----------
Add a method specifically for scheduling a polled/overdue group cacher work item

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/principals.py
    CalendarServer/trunk/calendarserver/tools/util.py
    CalendarServer/trunk/twistedcaldav/directory/directory.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_directory.py

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2013-04-19 20:52:47 UTC (rev 11070)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2013-04-19 21:29:57 UTC (rev 11071)
@@ -31,7 +31,7 @@
 
 from twistedcaldav.config import config
 from twistedcaldav.directory.directory import UnknownRecordTypeError, DirectoryError
-from twistedcaldav.directory.directory import scheduleNextGroupCachingUpdate
+from twistedcaldav.directory.directory import schedulePolledGroupCachingUpdate
 
 from calendarserver.tools.util import (
     booleanArgument, proxySubprincipal, action_addProxyPrincipal,
@@ -505,8 +505,8 @@
         membersProperty = davxml.GroupMemberSet(*memberURLs)
         yield subPrincipal.writeProperty(membersProperty, None)
         if store is not None:
-            # Schedule in the past so the queue poller picks it up quickly
-            yield scheduleNextGroupCachingUpdate(store, -10*60)
+            # Schedule work the PeerConnectionPool will pick up as overdue
+            yield schedulePolledGroupCachingUpdate(store)
 
 
 @inlineCallbacks

Modified: CalendarServer/trunk/calendarserver/tools/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/util.py	2013-04-19 20:52:47 UTC (rev 11070)
+++ CalendarServer/trunk/calendarserver/tools/util.py	2013-04-19 21:29:57 UTC (rev 11071)
@@ -50,7 +50,7 @@
 from twistedcaldav.directory import calendaruserproxy
 from twistedcaldav.directory.aggregate import AggregateDirectoryService
 from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
-from twistedcaldav.directory.directory import scheduleNextGroupCachingUpdate
+from twistedcaldav.directory.directory import schedulePolledGroupCachingUpdate
 from calendarserver.push.notifier import NotifierFactory
 
 from txdav.common.datastore.file import CommonDataStore
@@ -462,8 +462,8 @@
     (yield action_removeProxyPrincipal(rootResource, directory, store,
         principal, proxyPrincipal, proxyTypes=proxyTypes))
 
-    # Schedule in the past so the queue poller picks it up quickly
-    yield scheduleNextGroupCachingUpdate(store, -10*60)
+    # Schedule work the PeerConnectionPool will pick up as overdue
+    yield schedulePolledGroupCachingUpdate(store)
 
 
 
@@ -496,8 +496,8 @@
         (yield subPrincipal.writeProperty(membersProperty, None))
 
     if removed:
-        # Schedule in the past so the queue poller picks it up quickly
-        yield scheduleNextGroupCachingUpdate(store, -10*60)
+        # Schedule work the PeerConnectionPool will pick up as overdue
+        yield schedulePolledGroupCachingUpdate(store)
     returnValue(removed)
 
 

Modified: CalendarServer/trunk/twistedcaldav/directory/directory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/directory.py	2013-04-19 20:52:47 UTC (rev 11070)
+++ CalendarServer/trunk/twistedcaldav/directory/directory.py	2013-04-19 21:29:57 UTC (rev 11071)
@@ -59,7 +59,7 @@
 from xml.parsers.expat import ExpatError
 from plistlib import readPlistFromString
 from twext.enterprise.dal.record import fromTable
-from twext.enterprise.queue import WorkItem
+from twext.enterprise.queue import WorkItem, PeerConnectionPool
 from txdav.common.datastore.sql_tables import schema
 from twext.enterprise.dal.syntax import Delete
 
@@ -959,10 +959,20 @@
     txn = store.newTransaction()
     notBefore = datetime.datetime.utcnow() + datetime.timedelta(seconds=seconds)
     log.debug("Scheduling next group cacher update: %s" % (notBefore,))
-    yield txn.enqueue(GroupCacherPollingWork, notBefore=notBefore)
+    wp = (yield txn.enqueue(GroupCacherPollingWork, notBefore=notBefore))
     yield txn.commit()
+    returnValue(wp)
 
 
+def schedulePolledGroupCachingUpdate(store):
+    """
+    Schedules a group caching update work item in "the past" so PeerConnectionPool's
+    overdue-item logic picks it up quickly.
+    """
+    seconds = -PeerConnectionPool.queueProcessTimeout
+    return scheduleNextGroupCachingUpdate(store, seconds)
+
+
 def diffAssignments(old, new):
     """
     Compare two proxy assignment lists and return their differences in the form of

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_directory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_directory.py	2013-04-19 20:52:47 UTC (rev 11070)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_directory.py	2013-04-19 21:29:57 UTC (rev 11071)
@@ -20,12 +20,13 @@
 from twistedcaldav.test.util import TestCase
 from twistedcaldav.test.util import xmlFile, augmentsFile, proxiesFile, dirTest
 from twistedcaldav.config import config
-from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord, GroupMembershipCache, GroupMembershipCacheUpdater, diffAssignments
+from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord, GroupMembershipCache, GroupMembershipCacheUpdater, diffAssignments, schedulePolledGroupCachingUpdate
 from twistedcaldav.directory.xmlfile import XMLDirectoryService
 from twistedcaldav.directory.calendaruserproxyloader import XMLCalendarUserProxyLoader
 from twistedcaldav.directory import augment, calendaruserproxy
 from twistedcaldav.directory.util import normalizeUUID
 from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
+from txdav.common.datastore.test.util import buildStore
 
 import cPickle as pickle
 import uuid
@@ -738,8 +739,34 @@
             ])
         )
 
+    @inlineCallbacks
+    def testScheduling(self):
+        """
+        Exercise schedulePolledGroupCachingUpdate
+        """
 
+        groupCacher = StubGroupCacher()
 
+        def decorateTransaction(txn):
+            txn._groupCacher = groupCacher
+
+        store = yield buildStore(self, None)
+        store.callWithNewTransactions(decorateTransaction)
+        wp = (yield schedulePolledGroupCachingUpdate(store))
+        yield wp.whenExecuted()
+        self.assertTrue(groupCacher.called)
+
+    testScheduling.skip = "Fix WorkProposal to track delayed calls and cancel them"
+
+class StubGroupCacher(object):
+    def __init__(self):
+        self.called = False
+        self.updateSeconds = 99
+
+    def updateCache(self):
+        self.called = True
+
+
 class RecordsMatchingTokensTests(TestCase):
 
     @inlineCallbacks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130419/f6a67ba1/attachment.html>


More information about the calendarserver-changes mailing list