From 476a0b620dcc563420191449daabbecbcc179150 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Fri, 31 Jan 2014 17:32:10 +0100 Subject: [PATCH 1/2] [FIX] ir_cron: use the same search criteria as when listing job to excecyte when acquiring the lock on the job before its execution to prevent running already executed job bzr revid: laurent.mignon@acsone.eu-20140131163210-2sw8f2e5n4my5o5l --- openerp/addons/base/ir/ir_cron.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_cron.py b/openerp/addons/base/ir/ir_cron.py index 24a522f6309..77269c61550 100644 --- a/openerp/addons/base/ir/ir_cron.py +++ b/openerp/addons/base/ir/ir_cron.py @@ -216,12 +216,21 @@ class ir_cron(osv.osv): lock_cr = db.cursor() try: # Try to grab an exclusive lock on the job row from within the task transaction + # Restrict to the same conditions as for the search since the job may have already + # been run by an other thread when cron is running in multi thread lock_cr.execute("""SELECT * FROM ir_cron - WHERE id=%s + WHERE numbercall != 0 + AND active + AND nextcall <= (now() at time zone 'UTC') + AND id=%s FOR UPDATE NOWAIT""", (job['id'],), log_exceptions=False) + locked_job = lock_cr.fetchone() + if not locked_job: + _logger.debug("Job already %s executed by another process/thread. skipping it", job['name']) + continue # Got the lock on the job row, run its code _logger.debug('Starting job `%s`.', job['name']) job_cr = db.cursor() From ef974c7fe5d221c3b1de68f2b6eee2a30b2c01d7 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (Acsone)" Date: Wed, 5 Feb 2014 10:14:52 +0100 Subject: [PATCH 2/2] Fix log message bzr revid: laurent.mignon@acsone.eu-20140205091452-6mamu14lpevyjy28 --- openerp/addons/base/ir/ir_cron.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_cron.py b/openerp/addons/base/ir/ir_cron.py index 77269c61550..77c9835d9be 100644 --- a/openerp/addons/base/ir/ir_cron.py +++ b/openerp/addons/base/ir/ir_cron.py @@ -229,7 +229,7 @@ class ir_cron(osv.osv): locked_job = lock_cr.fetchone() if not locked_job: - _logger.debug("Job already %s executed by another process/thread. skipping it", job['name']) + _logger.debug("Job `%s` already executed by another process/thread. skipping it", job['name']) continue # Got the lock on the job row, run its code _logger.debug('Starting job `%s`.', job['name'])