diff --git a/trytond/ir/cron.py b/trytond/ir/cron.py index 9c14f471d8..55d3dad5a3 100644 --- a/trytond/ir/cron.py +++ b/trytond/ir/cron.py @@ -12,8 +12,6 @@ from trytond import pooler from trytond.osv import fields, OSV from trytond.netsvc import Agent -NEXT_WAIT = 60 - _INTERVALTYPES = { 'work_days': lambda interval: DateTime.RelativeDateTime(days=interval), 'days': lambda interval: DateTime.RelativeDateTime(days=interval), @@ -81,7 +79,7 @@ class Cron(OSV, Agent): fct = getattr(obj, func) fct(cursor, user, *args) - def pool_jobs(self, db_name, check=False): + def pool_jobs(self, db_name): #TODO Error treatment: exception, request, ... -> send request to user now = DateTime.now() try: @@ -121,9 +119,5 @@ class Cron(OSV, Agent): cursor.commit() finally: cursor.close() - #TODO improved to do at the min(min(nextcalls), time() + NEWT_WAIT) - if not check: - self.set_alarm(self.pool_jobs, int(time.time()) + NEXT_WAIT, - [db_name]) Cron() diff --git a/trytond/pooler.py b/trytond/pooler.py index be8d39ecba..578959057a 100644 --- a/trytond/pooler.py +++ b/trytond/pooler.py @@ -40,8 +40,6 @@ def get_db_and_pool(db_name, update_module=False, wizard=False, report=False, from module import load_modules load_modules(database, update_module, lang) - if not update_module: - pool.get('ir.cron').pool_jobs(database.dbname) if wizard: return database, pool_wizard if report: @@ -74,6 +72,9 @@ def get_db_only(db_name): def get_db(db_name): return get_db_and_pool(db_name)[0] +def get_db_list(): + return _DB.keys() + def get_pool(db_name, update_module=False, lang=None): pool = get_db_and_pool(db_name, update_module, lang=lang)[1] return pool diff --git a/trytond/trytond.py b/trytond/trytond.py index 0955364d28..228d22cdd3 100644 --- a/trytond/trytond.py +++ b/trytond/trytond.py @@ -206,8 +206,16 @@ class TrytonServer(object): if CONFIG['webdav']: webdavd.start() #DISPATCHER.run() + count = 0 while True: time.sleep(1) + count += 1 + if count == 60: + #TODO check if we don't need to run pool_jobs in a thread + for dbname in pooler.get_db_list(): + pool = pooler.get_pool(dbname) + pool.get('ir.cron').pool_jobs(dbname) + count = 0 if __name__ == "__main__": SERVER = TrytonServer()