[Checkins] SVN: zc.async/trunk/s add ``remove`` to queue API.
Internal a5.
Gary Poster
gary at zope.com
Tue Jul 1 17:27:46 EDT 2008
Log message for revision 87901:
add ``remove`` to queue API. Internal a5.
Changed:
U zc.async/trunk/setup.py
U zc.async/trunk/src/zc/async/CHANGES.txt
U zc.async/trunk/src/zc/async/README.txt
U zc.async/trunk/src/zc/async/interfaces.py
U zc.async/trunk/src/zc/async/queue.py
U zc.async/trunk/src/zc/async/queue.txt
-=-
Modified: zc.async/trunk/setup.py
===================================================================
--- zc.async/trunk/setup.py 2008-07-01 20:45:44 UTC (rev 87900)
+++ zc.async/trunk/setup.py 2008-07-01 21:27:46 UTC (rev 87901)
@@ -71,7 +71,7 @@
setup(
name='zc.async',
- version='1.3a4',
+ version='1.3a5',
packages=find_packages('src'),
package_dir={'':'src'},
zip_safe=False,
Modified: zc.async/trunk/src/zc/async/CHANGES.txt
===================================================================
--- zc.async/trunk/src/zc/async/CHANGES.txt 2008-07-01 20:45:44 UTC (rev 87900)
+++ zc.async/trunk/src/zc/async/CHANGES.txt 2008-07-01 21:27:46 UTC (rev 87901)
@@ -1,6 +1,8 @@
1.3 (unreleased)
================
+- added ``remove`` method on queue.
+
- added helpers for setting up and tearing down Zope 3 functional tests
(ftesting.py), and a discussion of how to write Zope 3 functional tests with
layers (zope.app.testing.functional) in ftesting.txt.
Modified: zc.async/trunk/src/zc/async/README.txt
===================================================================
--- zc.async/trunk/src/zc/async/README.txt 2008-07-01 20:45:44 UTC (rev 87900)
+++ zc.async/trunk/src/zc/async/README.txt 2008-07-01 21:27:46 UTC (rev 87901)
@@ -244,23 +244,56 @@
lambdas and other functions created dynamically. As we'll see below, the job
instance can help us out there somewhat by offering closure-like features.
---------------
-``queue.pull``
---------------
+-----------------------------------
+``queue.pull`` and ``queue.remove``
+-----------------------------------
If you put a job into a queue and it hasn't been claimed yet and you want to
-cancel the job, ``pull`` it from the queue.
+cancel the job, ``pull`` or ``remove`` it from the queue.
+The ``pull`` method removes the first job, or takes an integer index.
+
>>> len(queue)
0
- >>> job = queue.put(send_message)
+ >>> job1 = queue.put(send_message)
+ >>> job2 = queue.put(send_message)
>>> len(queue)
- 1
- >>> job is queue.pull()
+ 2
+ >>> job1 is queue.pull()
True
+ >>> list(queue) == [job2]
+ True
+ >>> job1 is queue.put(job1)
+ True
+ >>> list(queue) == [job2, job1]
+ True
+ >>> job1 is queue.pull(-1)
+ True
+ >>> job2 is queue.pull()
+ True
>>> len(queue)
0
+The ``remove`` method removes the specific given job.
+
+ >>> job1 = queue.put(send_message)
+ >>> job2 = queue.put(send_message)
+ >>> len(queue)
+ 2
+ >>> queue.remove(job1)
+ >>> list(queue) == [job2]
+ True
+ >>> job1 is queue.put(job1)
+ True
+ >>> list(queue) == [job2, job1]
+ True
+ >>> queue.remove(job1)
+ >>> list(queue) == [job2]
+ True
+ >>> queue.remove(job2)
+ >>> len(queue)
+ 0
+
---------------
Scheduled Calls
---------------
Modified: zc.async/trunk/src/zc/async/interfaces.py
===================================================================
--- zc.async/trunk/src/zc/async/interfaces.py 2008-07-01 20:45:44 UTC (rev 87900)
+++ zc.async/trunk/src/zc/async/interfaces.py 2008-07-01 21:27:46 UTC (rev 87901)
@@ -365,6 +365,9 @@
that dispatchers will not try to perform it.
"""
+ def remove(item):
+ """Removes item from queue or raises LookupError if not found."""
+
def claim(filter=None, default=None):
"""returns first due job that is available for the given filter,
removing it from the queue as appropriate; or None, if none are
Modified: zc.async/trunk/src/zc/async/queue.py
===================================================================
--- zc.async/trunk/src/zc/async/queue.py 2008-07-01 20:45:44 UTC (rev 87900)
+++ zc.async/trunk/src/zc/async/queue.py 2008-07-01 21:27:46 UTC (rev 87901)
@@ -386,6 +386,17 @@
return job
assert False, 'programmer error: the length appears to be incorrect.'
+ def remove(self, item):
+ for pop, ix, job in self._iter():
+ if job is item:
+ assert pop(ix) is job
+ self._length.change(-1)
+ job.assignerUUID = None
+ job.parent = None
+ break
+ else:
+ raise LookupError('item not in queue', item)
+
def claim(self, filter=None, default=None):
now = datetime.datetime.now(pytz.UTC)
if not self._length():
Modified: zc.async/trunk/src/zc/async/queue.txt
===================================================================
--- zc.async/trunk/src/zc/async/queue.txt 2008-07-01 20:45:44 UTC (rev 87900)
+++ zc.async/trunk/src/zc/async/queue.txt 2008-07-01 21:27:46 UTC (rev 87901)
@@ -51,10 +51,10 @@
Queues and Jobs
===============
-As described in the README, we can put jobs to be performed now in the
-queue, and jobs to be performed later. The collection can be
-introspected, and then agents can ``claim`` a job or simply remove it with
-``pull``; we'll examine the differences between these calls below.
+As described in the README, we can put jobs to be performed now in the queue,
+and jobs to be performed later. The collection can be introspected, and then
+agents can ``claim`` a job or simply remove it with ``pull`` or ``remove``.
+We'll examine the differences between these calls below.
We'll start by adding a job to be performed as soon as possible. Note
that we'll use a testing tool that lets us control the current time
@@ -183,6 +183,31 @@
>>> list(queue) == [job4, job3]
True
+The ``pull`` method takes the first item off the queue, or you can pass an
+index.
+
+The ``remove`` method lets you remove a specific job from the queue.
+
+ >>> queue.remove(job3)
+ >>> list(queue) == [job4]
+ True
+
+ >>> queue.remove(job4)
+ >>> list(queue)
+ []
+
+ >>> queue.remove(job4) # doctest: +ELLIPSIS
+ Traceback (most recent call last):
+ ...
+ LookupError: ('item not in queue', <zc.async.job.Job...>)
+
+ >>> job3 is queue.put(job3)
+ True
+ >>> job4 is queue.put(job4)
+ True
+ >>> list(queue) == [job4, job3]
+ True
+
Let's add another job without an explicit due date.
>>> job6 = queue.put(
More information about the Checkins
mailing list