Merge lp:~jfb-tempo-consulting/unifield-addons/us-440 into lp:unifield-addons

Proposed by jftempo
Status: Merged
Merged at revision: 4668
Proposed branch: lp:~jfb-tempo-consulting/unifield-addons/us-440
Merge into: lp:unifield-addons
Diff against target: 66 lines (+18/-10)
1 file modified
procurement/schedulers.py (+18/-10)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-addons/us-440
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+264135@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'procurement/schedulers.py'
--- procurement/schedulers.py 2015-07-01 07:15:26 +0000
+++ procurement/schedulers.py 2015-07-08 12:28:38 +0000
@@ -29,12 +29,17 @@
29import pooler29import pooler
30import tools30import tools
31from tools.translate import _31from tools.translate import _
3232from threading import Lock
33import logging
3334
34class procurement_order(osv.osv):35class procurement_order(osv.osv):
35 _inherit = 'procurement.order'36 _inherit = 'procurement.order'
36 37 __lock = False
37 38
39 def __init__(self, *a, **b):
40 self.__lock = Lock()
41 super(procurement_order, self).__init__(*a, **b)
42
38 def _hook_request_vals(self, cr, uid, *args, **kwargs):43 def _hook_request_vals(self, cr, uid, *args, **kwargs):
39 '''44 '''
40 Hook to change the request values45 Hook to change the request values
@@ -59,19 +64,21 @@
59 @param context: A standard dictionary for contextual values64 @param context: A standard dictionary for contextual values
60 @return: Dictionary of values65 @return: Dictionary of values
61 '''66 '''
67 logger = logging.getLogger('procure.confirm')
68
62 if context is None:69 if context is None:
63 context = {}70 context = {}
6471
72 locked = context.get('run_id')
65 try:73 try:
66 if use_new_cursor:74 if use_new_cursor:
67 cr = pooler.get_db(use_new_cursor).cursor()75 cr = pooler.get_db(use_new_cursor).cursor()
68 wf_service = netsvc.LocalService("workflow")76 wf_service = netsvc.LocalService("workflow")
6977
70 if context.get('run_id'):78 if locked:
71 run_ids = self.pool.get('procurement.purchase.compute.all.running').search(cr, uid, [], context=context)79 logger.info('Start scheduler with lock, try to acquire lock')
72 while len(run_ids) > 1:80 self.__lock.acquire()
73 time.sleep(5)81 logger.info('Lock acquired')
74 run_ids = self.pool.get('procurement.purchase.compute.all.running').search(cr, uid, [], context=context)
7582
76 procurement_obj = self.pool.get('procurement.order')83 procurement_obj = self.pool.get('procurement.order')
77 if not ids:84 if not ids:
@@ -166,11 +173,12 @@
166 self._hook_request_vals(cr, uid, request_vals=request_vals, context=context)173 self._hook_request_vals(cr, uid, request_vals=request_vals, context=context)
167 request.create(cr, uid, request_vals)174 request.create(cr, uid, request_vals)
168175
169 if context.get('run_id'):
170 self.pool.get('procurement.purchase.compute.all.running').unlink(cr, uid, [context.get('run_id')], context=context)
171 if use_new_cursor:176 if use_new_cursor:
172 cr.commit()177 cr.commit()
173 finally:178 finally:
179 if locked:
180 self.__lock.release()
181 logger.info('Lock released')
174 if use_new_cursor:182 if use_new_cursor:
175 try:183 try:
176 cr.close()184 cr.close()

Subscribers

People subscribed via source and target branches

to all changes: