X-Git-Url: https://git.llucax.com/z.facultad/75.52/sercom.git/blobdiff_plain/2344dcf6736372c1dd359a95819fb3c2e131afc2..e035633c5e57e3163f7df30a08ea0f239b058c7e:/start-sercom.py?ds=sidebyside diff --git a/start-sercom.py b/start-sercom.py index b32eb45..0ec9722 100644 --- a/start-sercom.py +++ b/start-sercom.py @@ -1,4 +1,9 @@ #!/usr/bin/python +# vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker : + +import locale +locale.setlocale(locale.LC_ALL, '') + import pkg_resources pkg_resources.require("TurboGears") @@ -13,13 +18,53 @@ import sys # look for setup.py in this directory. If it's not there, this script is # probably installed if len(sys.argv) > 1: - update_config(configfile=sys.argv[1], + update_config(configfile=sys.argv[1], modulename="sercom.config") elif exists(join(dirname(__file__), "setup.py")): update_config(configfile="dev.cfg",modulename="sercom.config") else: update_config(configfile="prod.cfg",modulename="sercom.config") +from sercom.model import InstanciaDeEntrega, 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.selectBy(inicio_proceso=None) + instancia = select.orderBy(InstanciaDeEntrega.q.fin)[0] + 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='juanca', queue=q) +#t = Thread(name='juanca', target=finalizer.run) +#t.start() + from sercom.controllers import Root start_server(Root()) +