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
1=== modified file 'procurement/schedulers.py'
2--- procurement/schedulers.py 2015-07-01 07:15:26 +0000
3+++ procurement/schedulers.py 2015-07-08 12:28:38 +0000
4@@ -29,12 +29,17 @@
5 import pooler
6 import tools
7 from tools.translate import _
8-
9+from threading import Lock
10+import logging
11
12 class procurement_order(osv.osv):
13 _inherit = 'procurement.order'
14-
15-
16+ __lock = False
17+
18+ def __init__(self, *a, **b):
19+ self.__lock = Lock()
20+ super(procurement_order, self).__init__(*a, **b)
21+
22 def _hook_request_vals(self, cr, uid, *args, **kwargs):
23 '''
24 Hook to change the request values
25@@ -59,19 +64,21 @@
26 @param context: A standard dictionary for contextual values
27 @return: Dictionary of values
28 '''
29+ logger = logging.getLogger('procure.confirm')
30+
31 if context is None:
32 context = {}
33
34+ locked = context.get('run_id')
35 try:
36 if use_new_cursor:
37 cr = pooler.get_db(use_new_cursor).cursor()
38 wf_service = netsvc.LocalService("workflow")
39
40- if context.get('run_id'):
41- run_ids = self.pool.get('procurement.purchase.compute.all.running').search(cr, uid, [], context=context)
42- while len(run_ids) > 1:
43- time.sleep(5)
44- run_ids = self.pool.get('procurement.purchase.compute.all.running').search(cr, uid, [], context=context)
45+ if locked:
46+ logger.info('Start scheduler with lock, try to acquire lock')
47+ self.__lock.acquire()
48+ logger.info('Lock acquired')
49
50 procurement_obj = self.pool.get('procurement.order')
51 if not ids:
52@@ -166,11 +173,12 @@
53 self._hook_request_vals(cr, uid, request_vals=request_vals, context=context)
54 request.create(cr, uid, request_vals)
55
56- if context.get('run_id'):
57- self.pool.get('procurement.purchase.compute.all.running').unlink(cr, uid, [context.get('run_id')], context=context)
58 if use_new_cursor:
59 cr.commit()
60 finally:
61+ if locked:
62+ self.__lock.release()
63+ logger.info('Lock released')
64 if use_new_cursor:
65 try:
66 cr.close()

Subscribers

People subscribed via source and target branches

to all changes: