[CalendarServer-changes] [14260] twext/trunk/twext/enterprise

source_changes at macosforge.org source_changes at macosforge.org
Wed Jan 7 11:45:08 PST 2015


Revision: 14260
          http://trac.calendarserver.org//changeset/14260
Author:   cdaboo at apple.com
Date:     2015-01-07 11:45:08 -0800 (Wed, 07 Jan 2015)
Log Message:
-----------
Work item that deletes all others in the same group when it runs.

Modified Paths:
--------------
    twext/trunk/twext/enterprise/dal/record.py
    twext/trunk/twext/enterprise/jobqueue.py

Modified: twext/trunk/twext/enterprise/dal/record.py
===================================================================
--- twext/trunk/twext/enterprise/dal/record.py	2015-01-07 19:41:38 UTC (rev 14259)
+++ twext/trunk/twext/enterprise/dal/record.py	2015-01-07 19:45:08 UTC (rev 14260)
@@ -480,9 +480,17 @@
         """
         Delete all rows from the table that corresponds to C{cls}.
         """
+        return cls.deletesome(transaction, None)
+
+
+    @classmethod
+    def deletesome(cls, transaction, where):
+        """
+        Delete all rows matching the where expression from the table that corresponds to C{cls}.
+        """
         return Delete(
             From=cls.table,
-            Where=None,
+            Where=where,
         ).on(transaction)
 
 

Modified: twext/trunk/twext/enterprise/jobqueue.py
===================================================================
--- twext/trunk/twext/enterprise/jobqueue.py	2015-01-07 19:41:38 UTC (rev 14259)
+++ twext/trunk/twext/enterprise/jobqueue.py	2015-01-07 19:45:08 UTC (rev 14260)
@@ -1144,6 +1144,23 @@
 
 
 
+class AggregatedWorkItem(WorkItem):
+    """
+    An L{WorkItem} that deletes all the others in the same group prior to running.
+    """
+
+    @inlineCallbacks
+    def beforeWork(self):
+        """
+        For safety just delete any others.
+        """
+
+        # Delete all other work items
+        yield self.deletesome(self.transaction, self.group)
+        returnValue(True)
+
+
+
 class RegeneratingWorkItem(SingletonWorkItem):
     """
     An L{SingletonWorkItem} that regenerates itself when work is done.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150107/b1f2e64f/attachment.html>


More information about the calendarserver-changes mailing list