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
=== 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-02-05 09:36:39 +0000
@@ -216,12 +216,21 @@
216 lock_cr = db.cursor()216 lock_cr = db.cursor()
217 try:217 try:
218 # Try to grab an exclusive lock on the job row from within the task transaction218 # Try to grab an exclusive lock on the job row from within the task transaction
219 # Restrict to the same conditions as for the search since the job may have already
220 # been run by an other thread when cron is running in multi thread
219 lock_cr.execute("""SELECT *221 lock_cr.execute("""SELECT *
220 FROM ir_cron222 FROM ir_cron
221 WHERE id=%s223 WHERE numbercall != 0
224 AND active
225 AND nextcall <= (now() at time zone 'UTC')
226 AND id=%s
222 FOR UPDATE NOWAIT""",227 FOR UPDATE NOWAIT""",
223 (job['id'],), log_exceptions=False)228 (job['id'],), log_exceptions=False)
224229
230 locked_job = lock_cr.fetchone()
231 if not locked_job:
232 _logger.debug("Job `%s` already executed by another process/thread. skipping it", job['name'])
233 continue
225 # Got the lock on the job row, run its code234 # Got the lock on the job row, run its code
226 _logger.debug('Starting job `%s`.', job['name'])235 _logger.debug('Starting job `%s`.', job['name'])
227 job_cr = db.cursor()236 job_cr = db.cursor()

Subscribers

People subscribed via source and target branches

to status/vote changes: