[CalendarServer-changes] [13984] twext/trunk/twext/enterprise/jobqueue.py
source_changes at macosforge.org
source_changes at macosforge.org
Sat Sep 20 07:14:07 PDT 2014
Revision: 13984
http://trac.calendarserver.org//changeset/13984
Author: cdaboo at apple.com
Date: 2014-09-20 07:14:07 -0700 (Sat, 20 Sep 2014)
Log Message:
-----------
Methods to wait until a specific job is done, or until specific types of work are complete.
Modified Paths:
--------------
twext/trunk/twext/enterprise/jobqueue.py
Modified: twext/trunk/twext/enterprise/jobqueue.py
===================================================================
--- twext/trunk/twext/enterprise/jobqueue.py 2014-09-19 21:05:34 UTC (rev 13983)
+++ twext/trunk/twext/enterprise/jobqueue.py 2014-09-20 14:14:07 UTC (rev 13984)
@@ -727,6 +727,53 @@
@classmethod
@inlineCallbacks
+ def waitJobDone(cls, txnCreator, reactor, timeout, jobID):
+ """
+ Wait for the specified job to complete. Only use this in tests
+ that need to wait for results from jobs.
+ """
+ t = time.time()
+ while True:
+ work = yield inTransaction(txnCreator, cls.query, expr=(cls.jobID == jobID))
+ if not work:
+ break
+ if time.time() - t > timeout:
+ returnValue(False)
+ d = Deferred()
+ reactor.callLater(0.1, lambda : d.callback(None))
+ yield d
+
+ returnValue(True)
+
+
+ @classmethod
+ @inlineCallbacks
+ def waitWorkDone(cls, txnCreator, reactor, timeout, workTypes):
+ """
+ Wait for the specified job to complete. Only use this in tests
+ that need to wait for results from jobs.
+ """
+ t = time.time()
+ while True:
+ count = 0
+ def _countTypes(txn):
+ for t in workTypes:
+ work = yield t.all()
+ count += len(work)
+ yield inTransaction(txnCreator, _countTypes)
+ if count == 0:
+ break
+ if time.time() - t > timeout:
+ returnValue(False)
+ d = Deferred()
+ reactor.callLater(0.1, lambda : d.callback(None))
+ yield d
+
+ returnValue(True)
+
+
+ @classmethod
+ @inlineCallbacks
def histogram(cls, txn):
"""
Generate a histogram of work items currently in the queue.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140920/89e1ae92/attachment.html>
More information about the calendarserver-changes
mailing list