24
24
from osv import fields
25
25
from osv import osv
33
# Enable/Disable performance monitoring
34
enable_monitor = False
36
class dm_perf_monitor(osv.osv): # {{{
37
_name = "dm.perf_monitor"
38
_descitption = "DM Performance Monitor"
41
'name' : fields.char('Function Name', size=64, required=True),
42
'model' : fields.char('Model Name', size=64, required=True),
43
'duration' : fields.float('Duration'),
44
'date' : fields.datetime('Date'),
48
'date' : lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
50
dm_perf_monitor() # }}}
52
def monitor(func): # {{{
54
def callf(*args, **kwargs):
55
time_start = time.time()
56
r = func(*args, **kwargs)
57
time_stop = time.time()
58
duration = time_stop - time_start
60
'name' : func.__name__,
61
'duration' : duration,
64
pooler.get_pool(args[1].dbname).get('dm.perf_monitor').create(args[1], args[2], vals)
70
class report_dm_performance_monitor(osv.osv):
71
_name = "report.dm.performance.monitor"
72
_description = "Performance monitor"
75
'name' : fields.char('Function Name', size=64, required=True),
76
'duration' : fields.float('Duration'),
80
tools.drop_view_if_exists(cr, 'report_dm_performance_monitor')
82
create or replace view report_dm_performance_monitor as (
86
avg(p.duration) as duration
92
report_dm_performance_monitor()
33
94
class dm_workitem(osv.osv): # {{{
34
95
_name = "dm.workitem"
55
116
res[wi.id] = wi.address_id and wi.address_id.email or ''
59
121
'step_id': fields.many2one('dm.offer.step', 'Offer Step',
60
122
ondelete="cascade", select="1"),
65
127
'Customer Address',
67
129
ondelete="cascade"),
68
'customer_id': fields.function(_customer_id, method=True, type='char', string='Customer Id'),
69
'customer_email': fields.function(_customer_email, method=True, type='char', string='Customer Email'),
130
'customer_id': fields.function(_customer_id, method=True, type='char',
131
string='Customer Id'),
132
'customer_email': fields.function(_customer_email, method=True,
133
type='char', string='Customer Email'),
70
134
'action_time': fields.datetime('Action Time', select="1"),
71
135
'source': fields.selection(_SOURCES, 'Source', required=True),
72
136
'error_msg': fields.text('System Message'),
73
# 'is_global': fields.boolean('Global Workitem'),
74
137
'is_preview': fields.boolean('Document Preview Workitem'),
75
138
'tr_from_id': fields.many2one('dm.offer.step.transition',
76
139
'Source Transition',
83
146
'source': lambda *a: 'address_id',
84
147
'state': lambda *a: 'pending',
85
# 'is_global': lambda *a: False,
86
148
'is_preview': lambda *a: False,
87
149
'is_realtime': lambda *a: True,
88
150
'action_time': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
95
157
wi_res = self.run(cr, uid, obj, context=context)
99
162
def _check_sysmsg(self, cr, uid, code, context=None):
100
163
""" Check action message code and set workitem log """
101
164
sysmsg_id = self.pool.get('dm.sysmsg').search(cr, uid,
111
174
'msg': "An unknown error has occured : %s" % code,
115
178
def run(self, cr, uid, wi, context={}):
116
179
logger = netsvc.Logger()
117
180
context['active_id'] = wi.id
152
""" Execute server action """
215
"Execute server action"
153
216
wi_res = server_obj.run(cr, uid, [wi.step_id.action_id.id], context)
154
217
""" Check returned code and set wi status """
155
218
wi_status = self._check_sysmsg(cr, uid, wi_res['code'],
158
""" Set workitem state and message """
221
"Set workitem state and message"
159
222
wr = self.write(cr, uid, [wi.id], {'state': wi_status['state'],
160
223
'error_msg':wi_status['msg']})
161
224
done = wi_status['result']
162
""" If workitem done then execute mail service action """
225
"If workitem done then execute mail service action"
165
228
doc_obj = self.pool.get(wi_res['model'])
180
243
'error_msg':ms_status['msg']})
183
""" Dont Execute Action if workitem is not to be processed """
246
"Dont Execute Action if workitem is not to be processed"
184
247
self.write(cr, uid, [wi.id], {'state': 'cancel',
185
248
'error_msg': 'Cancelled by : %s'% act_step})
258
321
""" Get workitems to process and run action """
259
322
ids = self.search(cr, uid, [('state', '=', 'pending'),
261
'<=', time.strftime('%Y-%m-%d %H:%M:%S')),
323
('action_time','<=', time.strftime('%Y-%m-%d %H:%M:%S')),
262
324
('is_realtime', '=', False)])
263
325
for wi in self.browse(cr, uid, ids[:MAX_SIZE], context=context):
264
326
wi_res = self.run(cr, uid, wi, context=context)
294
356
'source': lambda *a: 'address_id',
297
360
def create(self, cr, uid, vals, context={}):
298
361
id = super(dm_event,self).create(cr, uid, vals, context)
299
362
obj = self.browse(cr, uid, id)
302
365
[('step_from_id', '=', obj.step_id.id),
303
366
('condition_id', '=', obj.trigger_type_id.id)])
305
netsvc.Logger().notifyChannel('dm event case', netsvc.LOG_WARNING, "There is no transition %s at this step : %s"% (obj.trigger_type_id.name, obj.step_id.code))
306
raise osv.except_osv('Warning', "There is no outgoing transition %s at this step : %s"% (obj.trigger_type_id.name, obj.step_id.code))
368
netsvc.Logger().notifyChannel('dm event case', netsvc.LOG_WARNING,
369
"There is no transition %s at this step : %s"% (obj.trigger_type_id.name,
371
raise osv.except_osv('Warning',
372
"There is no outgoing transition %s at this step : %s"% (obj.trigger_type_id.name,
308
376
for tr in self.pool.get('dm.offer.step.transition').browse(cr, uid,
310
378
if obj.action_time: