Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

v0.5 -- fixing for update

  • Loading branch information...
commit a854a3248f26ef300b90e423967dae6e0b84d806 1 parent 081060d
@dmclain authored
Showing with 8 additions and 5 deletions.
  1. +1 −1  scrapy_heroku/__init__.py
  2. +7 −4 scrapy_heroku/spiderqueue.py
View
2  scrapy_heroku/__init__.py
@@ -1,2 +1,2 @@
-__version__ = (0, 4, 0)
+__version__ = (0, 5, 0)
View
11 scrapy_heroku/spiderqueue.py
@@ -35,18 +35,21 @@ def _execute(self, q, args=None, results=True):
cursor = self.conn.cursor()
cursor.execute(q, args)
if results:
- results = cursor.fetchall()
+ try:
+ results = list(cursor)
+ except psycopg2.ProgrammingError:
+ results = []
cursor.close()
return results
def put(self, message, priority=0.0):
args = (priority, self.encode(message))
q = "insert into %s (priority, message) values (%%s,%%s);" % self.table
- self._execute(q, args)
+ self._execute(q, args, results=False)
self.conn.commit()
def pop(self):
- q = "select for update id, message from %s order by priority desc limit 1;" \
+ q = "select id, message from %s order by priority desc limit 1 for update;" \
% self.table
results = self._execute(q)
if len(results) == 0:
@@ -61,7 +64,7 @@ def pop(self):
return self.decode(msg)
def remove(self, func):
- q = "select for update id, message from %s" % self.table
+ q = "select id, message from %s for update" % self.table
n = 0
for mid, msg in self.conn.execute(q):
if func(self.decode(msg)):
Please sign in to comment.
Something went wrong with that request. Please try again.