X-Git-Url: https://git.llucax.com/software/sercom.git/blobdiff_plain/43ba30161aa509976ea977e28b5141529ac00934..836e60188a6e0e1e6f7938dc9b8246a8ca92fd5b:/start-sercom.py diff --git a/start-sercom.py b/start-sercom.py index 45625c8..fd1c7e2 100644 --- a/start-sercom.py +++ b/start-sercom.py @@ -1,4 +1,5 @@ #!/usr/bin/python +# vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker : import locale locale.setlocale(locale.LC_ALL, '') @@ -24,6 +25,55 @@ elif exists(join(dirname(__file__), "setup.py")): else: update_config(configfile="prod.cfg",modulename="sercom.config") +from sercom.model import InstanciaDeEntrega, Entrega, AND, hub +from sercom.finalizer import Finalizer +from threading import Thread +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: + select = InstanciaDeEntrega.select(AND( + InstanciaDeEntrega.q.inicio_proceso == None, + InstanciaDeEntrega.q.fin <= datetime.now())) + instancia = select.orderBy(InstanciaDeEntrega.q.fin)[0] + n = Entrega.selectBy(instancia=instancia, fin=None).count() + if n: + log.debug(_(u'Esperando para procesar instancia (%s), ' + 'faltan probar %s entregas'), instancia.shortrepr(), + n) + time.sleep(30) + continue + instancia.inicio_proceso = datetime.now() + finally: + hub.commit() + return instancia.id + except IndexError: + log.debug(_(u'No hay instancias de entrega sin finalizar')) + time.sleep(30) # TODO config? + except Exception, e: + if isinstance(e, SystemExit): + raise + log.exception('Queue: ') + time.sleep(30) # TODO config? + return None +#}}} + +#q = Queue() +#finalizer = Finalizer(name='finalizer', queue=q) +#t = Thread(name='finalizer', target=finalizer.run) +#t.start() + from sercom.controllers import Root start_server(Root()) +