1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import datetime
import time
import netsvc
from osv import fields,osv
class ir_cron(osv.osv):
_inherit = "ir.cron"
ALLOWED_CRON_SLIPPAGE = 3600 # the number of seconds cron is allowed to fall behind
def sanity_check(self, cr, uid, context=None):
self.check_if_jobs_stalled(cr,uid,context)
return 0
def check_if_jobs_stalled(self, cr, uid, context):
case_id = self.pool.get('crm.helpdesk').sanity_test_create_stub_case(cr,uid,context,
'Cron Jobs Stalled',
""" This is a stub to track incidents of Cron jobs not running regularly.
""",
'ir_cron_check_if_jobs_stalled')
now = datetime.datetime.now()
oldest_timestamp_allowed = now - datetime.timedelta(0,self.ALLOWED_CRON_SLIPPAGE)
oldest_timestamp_allowed_str = oldest_timestamp_allowed.strftime( '%Y-%m-%d %H:%M:%S' )
cron_ids = self.search(cr,uid,[
('active','=','t'),
('nextcall','<',oldest_timestamp_allowed_str)
])
if not cron_ids:
return # horray, no weirdness
problem_writeup = "The following Cron Entries appear to have stalled:\n\n"
for cron_data in self.browse(cr,uid,cron_ids):
problem_writeup += "%i: %s last scheduled call was %s\n\n" \
% ( cron_data.id, cron_data.name, cron_data.nextcall )
problem_writeup += "\n\n"
# now that we've finished documenting the problem let's notify the
# appropriate users
self.pool.get('crm.helpdesk').sanity_test_log(
cr, uid, context,
case_id,
problem_writeup
)
ir_cron()
|