Merge lp:~acsone-openerp/openobject-server/7.0-bug-1274997-cron into lp:openobject-server/7.0

Proposed by Laurent Mignon (Acsone)
Status: Needs review
Proposed branch: lp:~acsone-openerp/openobject-server/7.0-bug-1274997-cron
Merge into: lp:openobject-server/7.0
Diff against target: 26 lines (+10/-1)
1 file modified
openerp/addons/base/ir/ir_cron.py (+10/-1)
To merge this branch: bzr merge lp:~acsone-openerp/openobject-server/7.0-bug-1274997-cron
Reviewer Review Type Date Requested Status
Laurent Mignon (Acsone) (community) Approve
OpenERP Core Team Pending
Review via email: mp+204289@code.launchpad.net

Description of the change

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

To post a comment you must log in.
Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :

Change status from 'Merged' to 'Needs review' since the fix has only been applied on trunk but not on the 7.0 branch.

review: Needs Resubmitting
Revision history for this message
Lionel Sausin - Initiatives/Numérigraphe (ls-initiatives) wrote :

Laurent you should change your vote as "Resubmit" means it can't be merge now and you must submit it again later.

Revision history for this message
Laurent Mignon (Acsone) (lmi) :
review: Approve

Unmerged revisions

5218. By Laurent Mignon (Acsone)

Fix log message

5217. By Laurent Mignon (Acsone)

[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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/ir/ir_cron.py'
2--- openerp/addons/base/ir/ir_cron.py 2013-04-18 01:04:10 +0000
3+++ openerp/addons/base/ir/ir_cron.py 2014-02-05 09:15:26 +0000
4@@ -216,12 +216,21 @@
5 lock_cr = db.cursor()
6 try:
7 # Try to grab an exclusive lock on the job row from within the task transaction
8+ # Restrict to the same conditions as for the search since the job may have already
9+ # been run by an other thread when cron is running in multi thread
10 lock_cr.execute("""SELECT *
11 FROM ir_cron
12- WHERE id=%s
13+ WHERE numbercall != 0
14+ AND active
15+ AND nextcall <= (now() at time zone 'UTC')
16+ AND id=%s
17 FOR UPDATE NOWAIT""",
18 (job['id'],), log_exceptions=False)
19
20+ locked_job = lock_cr.fetchone()
21+ if not locked_job:
22+ _logger.debug("Job `%s` already executed by another process/thread. skipping it", job['name'])
23+ continue
24 # Got the lock on the job row, run its code
25 _logger.debug('Starting job `%s`.', job['name'])
26 job_cr = db.cursor()