2 # vim: set et sw=4 sts=4 encoding=utf-8 foldmethod=marker :
5 locale.setlocale(locale.LC_ALL, '')
8 pkg_resources.require("TurboGears")
10 from turbogears import update_config, start_server
12 cherrypy.lowercase_api = True
16 # first look on the command line for a desired config file,
17 # if it's not on the command line, then
18 # look for setup.py in this directory. If it's not there, this script is
21 update_config(configfile=sys.argv[1],
22 modulename="sercom.config")
23 elif exists(join(dirname(__file__), "setup.py")):
24 update_config(configfile="dev.cfg",modulename="sercom.config")
26 update_config(configfile="prod.cfg",modulename="sercom.config")
28 from sercom.model import InstanciaDeEntrega, Entrega, AND, hub
29 from sercom.finalizer import Finalizer
30 from threading import Thread
31 from datetime import datetime
35 log = logging.getLogger('sercom.tester')
37 class Queue(object): #{{{
45 select = InstanciaDeEntrega.select(AND(
46 InstanciaDeEntrega.q.inicio_proceso == None,
47 InstanciaDeEntrega.q.fin <= datetime.now()))
48 instancia = select.orderBy(InstanciaDeEntrega.q.fin)[0]
49 n = Entrega.selectBy(instancia=instancia, fin=None).count()
51 log.debug(_(u'Esperando para procesar instancia (%s), '
52 'faltan probar %s entregas'), instancia.shortrepr(),
56 instancia.inicio_proceso = datetime.now()
61 log.debug(_(u'No hay instancias de entrega sin finalizar'))
62 time.sleep(30) # TODO config?
64 if isinstance(e, SystemExit):
66 log.exception('Queue: ')
67 time.sleep(30) # TODO config?
72 #finalizer = Finalizer(name='juanca', queue=q)
73 #t = Thread(name='juanca', target=finalizer.run)
76 from sercom.controllers import Root