Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

transaction commit refactor

  • Loading branch information...
commit a8349fa5c36de02d309a554b9d3b6be081c413ef 1 parent fddf54e
Dave McLain authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 scrapy_heroku/spiderqueue.py
12 scrapy_heroku/spiderqueue.py
View
@@ -29,11 +29,11 @@ def __init__(self, config, table='scrapy_queue'):
" priority real, " \
" message text);" % table
self._execute(q, results=False)
+ self.conn.commit()
def _execute(self, q, args=None, results=True):
cursor = self.conn.cursor()
cursor.execute(q, args)
- self.conn.commit()
if results:
results = cursor.fetchall()
cursor.close()
@@ -43,6 +43,7 @@ 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.conn.commit()
def pop(self):
q = "select for update id, message from %s order by priority desc limit 1;" \
@@ -75,15 +76,20 @@ def remove(self, func):
def clear(self):
self._execute("delete from %s" % self.table, results=False)
+ self.conn.commit()
def __len__(self):
q = "select count(*) from %s" % self.table
- return self._execute(q)[0][0]
+ result = self._execute(q)[0][0]
+ self.conn.commit()
+ return result
def __iter__(self):
q = "select message, priority from %s order by priority desc" % \
self.table
- return ((self.decode(x), y) for x, y in self._execute(q))
+ result = ((self.decode(x), y) for x, y in self._execute(q))
+ self.conn.commit()
+ return result
def encode(self, obj):
return obj
Please sign in to comment.
Something went wrong with that request. Please try again.