[IMP] cron: minor cleaning.

bzr revid: vmt@openerp.com-20110714151113-v07yr2rneqafbnni
This commit is contained in:
Vo Minh Thu 2011-07-14 17:11:13 +02:00
parent 2f115c21aa
commit 4b8708fb10
3 changed files with 15 additions and 22 deletions

View File

@ -108,8 +108,8 @@ if config['db_name']:
openerp.tools.convert_yaml_import(cr, 'base', file(config["test_file"]), {}, 'test', True)
cr.rollback()
# jobs will start to be processed later, when start_agent below is called.
registry.start_cron_thread()
# jobs will start to be processed later, when openerp.cron.start_master_thread below is called.
registry.schedule_cron_jobs()
cr.close()

View File

@ -105,8 +105,7 @@ class ir_cron(osv.osv):
def _handle_callback_exception(self, cr, uid, model, func, args, job_id, job_exception):
cr.rollback()
logger=logging.getLogger('cron')
logger.exception("Call of self.pool.get('%s').%s(cr, uid, *%r) failed in Job %s" % (model, func, args, job_id))
self._logger.exception("Call of self.pool.get('%s').%s(cr, uid, *%r) failed in Job %s" % (model, func, args, job_id))
def _callback(self, cr, uid, model, func, args, job_id):
args = str2tuple(args)
@ -229,16 +228,6 @@ class ir_cron(osv.osv):
cr.commit()
cr.close()
def restart_all(self):
import openerp.models.registry
for dbname in openerp.models.registry.RegistryManager.registries:
self.restart(self, dbname)
def restart(self, dbname):
openerp.cron.cancel(dbname)
# Reschedule cron processing job asap, but not in the current thread
openerp.cron.schedule_in_advance(time.time(), dbname)
def update_running_cron(self, cr):
# Verify whether the server is already started and thus whether we need to commit
# immediately our changes and restart the cron agent in order to apply the change
@ -249,7 +238,7 @@ class ir_cron(osv.osv):
# when the server is only starting or loading modules (hence the test on pool._init).
if not self.pool._init:
cr.commit()
self.restart(cr.dbname)
openerp.cron.schedule_in_advance(1, self.pool.db.dbname)
def create(self, cr, uid, vals, context=None):
res = super(ir_cron, self).create(cr, uid, vals, context=context)

View File

@ -84,8 +84,16 @@ class Registry(object):
return res
def start_cron_thread(self):
self.get('ir.cron').restart(self.db.dbname)
def schedule_cron_jobs(self):
""" Make the cron thread care about this registry/database jobs.
This will initiate the cron thread to check for any pending jobs for
this registry/database as soon as possible. Then it will continously
monitors the ir.cron model for future jobs. See openerp.cron for
details.
"""
openerp.cron.schedule_in_advance(1, self.db.dbname)
class RegistryManager(object):
@ -100,7 +108,6 @@ class RegistryManager(object):
# Accessed through the methods below.
registries = {}
@classmethod
def get(cls, db_name, force_demo=False, status=None, update_module=False,
pooljobs=True):
@ -113,7 +120,6 @@ class RegistryManager(object):
update_module, pooljobs)
return registry
@classmethod
def new(cls, db_name, force_demo=False, status=None,
update_module=False, pooljobs=True):
@ -148,11 +154,10 @@ class RegistryManager(object):
cr.close()
if pooljobs:
registry.start_cron_thread()
registry.schedule_cron_jobs()
return registry
@classmethod
def delete(cls, db_name):
""" Delete the registry linked to a given database.
@ -170,7 +175,6 @@ class RegistryManager(object):
openerp.tools.cache.clean_caches_for_db(db_name)
openerp.cron.cancel(db_name)
@classmethod
def delete_all(cls):
""" Delete all the registries. """