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

Proposed by Laurent Mignon (Acsone)
Status: Merged
Merged at revision: 5323
Proposed branch: lp:~acsone-openerp/ocb-server/7.0-bug-1274997-cron
Merge into: lp:ocb-server
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/ocb-server/7.0-bug-1274997-cron
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Alexandre Fayolle - camptocamp code review, no test Approve
Holger Brunn (Therp) code review Approve
Review via email: mp+204298@code.launchpad.net

Description of the change

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

To post a comment you must log in.
5243. By Laurent Mignon (Acsone)

Fix log message

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Thanks for this! I think I encountered the same problem once, but instead of fixing it properly, I distributed the calls over the hour, then you work around the problem I guess.

review: Approve (code review)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

Given the scenario, the patch looks safe.

review: Approve (code review, no test)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) :
review: Approve (code review)

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:36:39 +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()

Subscribers

People subscribed via source and target branches

to status/vote changes: