loolmeh / queues

Automatically exported from code.google.com/p/queues
MIT License
0 stars 0 forks source link

beanstalkd backend doesn't work with latest beanstalkd #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Install current beanstalkd 1.4.6
2. Install queues 0.6.1
3. Attempt to write and read to the queue

I believe the backend needs to be updated to use the .watch(NAME) method on the 
beanstalk connection, and I think the reads also need to use the timeout to 
beanstalk's reserve() method, so that the backend can return None if there is 
nothing in the queue rather than waiting for something to arrive.

Original issue reported on code.google.com by gregplay...@gmail.com on 4 Feb 2011 at 3:50

GoogleCodeExporter commented 9 years ago
I've modified the backends/beanstalkd.py file as follows:

--- a/lib/queues/backends/beanstalkd.py
+++ b/lib/queues/backends/beanstalkd.py
@@ -31,12 +31,16 @@ class Queue(BaseQueue):
         self.backend = 'beanstalkd'
         self.name = name
         self._connection.use(name)
+        self._connection.watch(name)

     def read(self):
         try:
-            job = self._connection.reserve()
-            message = job.body
-            job.delete()
+            job = self._connection.reserve(timeout=0)
+            if job:
+                message = job.body
+                job.delete()
+            else:
+                message = None
             return message
         except (beanstalkc.DeadlineSoon, beanstalkc.CommandFailed, beanstalkc.UnexpectedResponse), e:
             raise QueueException, e

Original comment by gregplay...@gmail.com on 4 Feb 2011 at 3:52