Fix ir.cron to not run in a separate thread
Fix issue69
This commit is contained in:
1 parent
be997ce427
commit
8cb58f5b03
3 files changed
+12
-9
No files matched your search
+1
-7
@@ -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()
|
||||
+3
-2
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user