def get_next(self):
'''Gets the next pending device.
Returns:
Dict: The next pending device as a dictionary object
with the names of the rows as keys.
'''
proc = 'main_db.get_next'
# User a special cursor which returns results as dicts
with self.conn, self.conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute('''
SELECT * FROM
pending
WHERE
working= FALSE
ORDER BY pending_id ASC LIMIT 1
''')
output = cur.fetchone()
# Mark the new entry as being worked on
if output:
cur.execute('''
UPDATE pending
SET working= TRUE
WHERE pending_id= %s
''',
(output['pending_id'],))
# Return the next device
output = dict(output)
return output
else: return None
评论列表
文章目录