← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~lmi/ocb-server/7.0-bug-1274997-cron into lp:ocb-server

 

Laurent Mignon (Acsone) has proposed merging lp:~lmi/ocb-server/7.0-bug-1274997-cron into lp:ocb-server.

Requested reviews:
  OpenERP Community Backports Team (ocb)
Related bugs:
  Bug #1274997 in OpenERP Community Backports (Server): "Same task executed several times at same time when cron is runnning in multi thread"
  https://bugs.launchpad.net/ocb-server/+bug/1274997

For more details, see:
https://code.launchpad.net/~lmi/ocb-server/7.0-bug-1274997-cron/+merge/204298

Automatically derived from https://code.launchpad.net/~acsone-openerp/openobject-server/7.0-bug-1274997-cron for https://code.launchpad.net/~openerp/openobject-server/7.0. Below is a copy of the original description.

solve lp:1274997
use the same search criteria as when listing job to excecute when acquiring the lock on the job before its execution to prevent running already executed job when the cron is running in multi thread
-- 
https://code.launchpad.net/~lmi/ocb-server/7.0-bug-1274997-cron/+merge/204298
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~lmi/ocb-server/7.0-bug-1274997-cron into lp:ocb-server.
=== modified file 'openerp/addons/base/ir/ir_cron.py'
--- openerp/addons/base/ir/ir_cron.py	2013-04-18 01:04:10 +0000
+++ openerp/addons/base/ir/ir_cron.py	2014-01-31 17:52:30 +0000
@@ -216,12 +216,21 @@
             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()


Follow ups