[IMP] cron: minor cleaning.
bzr revid: vmt@openerp.com-20110714151113-v07yr2rneqafbnni
This commit is contained in:
parent
2f115c21aa
commit
4b8708fb10
|
@ -108,8 +108,8 @@ if config['db_name']:
|
||||||
openerp.tools.convert_yaml_import(cr, 'base', file(config["test_file"]), {}, 'test', True)
|
openerp.tools.convert_yaml_import(cr, 'base', file(config["test_file"]), {}, 'test', True)
|
||||||
cr.rollback()
|
cr.rollback()
|
||||||
|
|
||||||
# jobs will start to be processed later, when start_agent below is called.
|
# jobs will start to be processed later, when openerp.cron.start_master_thread below is called.
|
||||||
registry.start_cron_thread()
|
registry.schedule_cron_jobs()
|
||||||
|
|
||||||
cr.close()
|
cr.close()
|
||||||
|
|
||||||
|
|
|
@ -105,8 +105,7 @@ class ir_cron(osv.osv):
|
||||||
|
|
||||||
def _handle_callback_exception(self, cr, uid, model, func, args, job_id, job_exception):
|
def _handle_callback_exception(self, cr, uid, model, func, args, job_id, job_exception):
|
||||||
cr.rollback()
|
cr.rollback()
|
||||||
logger=logging.getLogger('cron')
|
self._logger.exception("Call of self.pool.get('%s').%s(cr, uid, *%r) failed in Job %s" % (model, func, args, job_id))
|
||||||
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):
|
def _callback(self, cr, uid, model, func, args, job_id):
|
||||||
args = str2tuple(args)
|
args = str2tuple(args)
|
||||||
|
@ -229,16 +228,6 @@ class ir_cron(osv.osv):
|
||||||
cr.commit()
|
cr.commit()
|
||||||
cr.close()
|
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):
|
def update_running_cron(self, cr):
|
||||||
# Verify whether the server is already started and thus whether we need to commit
|
# 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
|
# 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).
|
# when the server is only starting or loading modules (hence the test on pool._init).
|
||||||
if not self.pool._init:
|
if not self.pool._init:
|
||||||
cr.commit()
|
cr.commit()
|
||||||
self.restart(cr.dbname)
|
openerp.cron.schedule_in_advance(1, self.pool.db.dbname)
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
def create(self, cr, uid, vals, context=None):
|
||||||
res = super(ir_cron, self).create(cr, uid, vals, context=context)
|
res = super(ir_cron, self).create(cr, uid, vals, context=context)
|
||||||
|
|
|
@ -84,8 +84,16 @@ class Registry(object):
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def start_cron_thread(self):
|
def schedule_cron_jobs(self):
|
||||||
self.get('ir.cron').restart(self.db.dbname)
|
""" 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):
|
class RegistryManager(object):
|
||||||
|
@ -100,7 +108,6 @@ class RegistryManager(object):
|
||||||
# Accessed through the methods below.
|
# Accessed through the methods below.
|
||||||
registries = {}
|
registries = {}
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get(cls, db_name, force_demo=False, status=None, update_module=False,
|
def get(cls, db_name, force_demo=False, status=None, update_module=False,
|
||||||
pooljobs=True):
|
pooljobs=True):
|
||||||
|
@ -113,7 +120,6 @@ class RegistryManager(object):
|
||||||
update_module, pooljobs)
|
update_module, pooljobs)
|
||||||
return registry
|
return registry
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(cls, db_name, force_demo=False, status=None,
|
def new(cls, db_name, force_demo=False, status=None,
|
||||||
update_module=False, pooljobs=True):
|
update_module=False, pooljobs=True):
|
||||||
|
@ -148,11 +154,10 @@ class RegistryManager(object):
|
||||||
cr.close()
|
cr.close()
|
||||||
|
|
||||||
if pooljobs:
|
if pooljobs:
|
||||||
registry.start_cron_thread()
|
registry.schedule_cron_jobs()
|
||||||
|
|
||||||
return registry
|
return registry
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, db_name):
|
def delete(cls, db_name):
|
||||||
""" Delete the registry linked to a given database.
|
""" 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.tools.cache.clean_caches_for_db(db_name)
|
||||||
openerp.cron.cancel(db_name)
|
openerp.cron.cancel(db_name)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete_all(cls):
|
def delete_all(cls):
|
||||||
""" Delete all the registries. """
|
""" Delete all the registries. """
|
||||||
|
|
Loading…
Reference in New Issue