+from datetime import datetime
+import time
+import logging
+
+log = logging.getLogger('sercom.tester')
+
+class Queue(object):
+ def __init__(self):
+ self.go_on = True
+ def get(self):
+ while self.go_on:
+ try:
+ hub.begin()
+ try:
+ e = Entrega.selectBy(inicio=None).orderBy(Entrega.q.fecha)[0]
+ e.inicio = datetime.now()
+ finally:
+ hub.commit()
+ return e.id
+ except IndexError:
+ log.debug(_(u'No hay entregas pendientes'))
+ time.sleep(5) # TODO config?
+ except Exception, e:
+ if isinstance(e, SystemExit):
+ raise
+ log.exception('Queue: ')
+ return None