From 6fe5728c462e90b43e8bd97a7699c9ac0240cf7e Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 16 Feb 2011 15:22:42 +0100 Subject: [PATCH] [FIX] ir.cron: avoid starting cron engine too early during server startup when ir.cron records are touched bzr revid: odo@openerp.com-20110216142242-gzd3029jq0le5cb0 --- bin/addons/base/ir/ir_cron.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/bin/addons/base/ir/ir_cron.py b/bin/addons/base/ir/ir_cron.py index 94e8f7d9ff8..2ab8819792a 100644 --- a/bin/addons/base/ir/ir_cron.py +++ b/bin/addons/base/ir/ir_cron.py @@ -149,22 +149,31 @@ class ir_cron(osv.osv, netsvc.Agent): # Reschedule cron processing job asap, but not in the current thread self.setAlarm(self._poolJobs, time.time(), dbname, 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 + # immediately. The commit() is needed because as soon as the cron is (re)started it + # will query the database with its own cursor, possibly before the end of the + # current transaction. + # This commit() is not an issue in most cases, but we must absolutely avoid it + # 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) + def create(self, cr, uid, vals, context=None): res = super(ir_cron, self).create(cr, uid, vals, context=context) - cr.commit() - self.restart(cr.dbname) + self.update_running_cron(cr) return res def write(self, cr, user, ids, vals, context=None): res = super(ir_cron, self).write(cr, user, ids, vals, context=context) - cr.commit() - self.restart(cr.dbname) + self.update_running_cron(cr) return res def unlink(self, cr, uid, ids, context=None): res = super(ir_cron, self).unlink(cr, uid, ids, context=context) - cr.commit() - self.restart(cr.dbname) + self.update_running_cron(cr) return res ir_cron()