Merge lp:~ajite/openobject-addons/elico-7.0-add-0003 into lp:~openerp-community/openobject-addons/elico-7.0

Status: Merged
Merge reported by: Eric Caudal - www.elico-corp.com
Merged at revision: not available
Proposed branch: lp:~ajite/openobject-addons/elico-7.0-add-0003
Merge into: lp:~openerp-community/openobject-addons/elico-7.0
Diff against target: 171 lines (+150/-0)
4 files modified
cron_watcher/__init__.py (+22/-0)
cron_watcher/__openerp__.py (+41/-0)
cron_watcher/cron.py (+65/-0)
cron_watcher/cron_data.xml (+22/-0)
To merge this branch: bzr merge lp:~ajite/openobject-addons/elico-7.0-add-0003
Reviewer Review Type Date Requested Status
LIN Yu Pending
Review via email: mp+219643@code.launchpad.net

Description of the change

Added the cron watcher module. This module sends notification to a group named "Cron Watcher" when a cron job has not run for X minutes.

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=== added directory 'cron_watcher'
2=== added file 'cron_watcher/__init__.py'
3--- cron_watcher/__init__.py 1970-01-01 00:00:00 +0000
4+++ cron_watcher/__init__.py 2014-05-15 07:16:29 +0000
5@@ -0,0 +1,22 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# OpenERP, Open Source Management Solution
10+# Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
11+# Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com>
12+#
13+# This program is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU Affero General Public License as
15+# published by the Free Software Foundation, either version 3 of the
16+# License, or (at your option) any later version.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU Affero General Public License for more details.
22+#
23+# You should have received a copy of the GNU Affero General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25+#
26+##############################################################################
27+import cron
28
29=== added file 'cron_watcher/__openerp__.py'
30--- cron_watcher/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ cron_watcher/__openerp__.py 2014-05-15 07:16:29 +0000
32@@ -0,0 +1,41 @@
33+# -*- coding: utf-8 -*-
34+##############################################################################
35+#
36+# OpenERP, Open Source Management Solution
37+# Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
38+# Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com>
39+#
40+# This program is free software: you can redistribute it and/or modify
41+# it under the terms of the GNU Affero General Public License as
42+# published by the Free Software Foundation, either version 3 of the
43+# License, or (at your option) any later version.
44+#
45+# This program is distributed in the hope that it will be useful,
46+# but WITHOUT ANY WARRANTY; without even the implied warranty of
47+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48+# GNU Affero General Public License for more details.
49+#
50+# You should have received a copy of the GNU Affero General Public License
51+# along with this program. If not, see <http://www.gnu.org/licenses/>.
52+#
53+##############################################################################
54+{'name': 'Cron Watcher',
55+ 'version': '0.1',
56+ 'category': 'Tools',
57+ 'depends': ['base', 'mail'],
58+ 'author': 'Elico Corp',
59+ 'license': 'AGPL-3',
60+ 'website': 'https://www.elico-corp.com',
61+ 'description': """
62+Sends notification to a group named "Cron Watcher" when a cron job has not run
63+for X minutes.
64+
65+X can be defined in "Settings", "Scheduler Actions", "Cron Watcher",
66+"Technical Data", "Arguments"
67+ * 5 minutes = (5,)
68+ * 10 minutes = (10,)
69+ * etc...
70+""",
71+ 'data': ['cron_data.xml'],
72+ 'installable': True,
73+ 'application': False}
74
75=== added file 'cron_watcher/cron.py'
76--- cron_watcher/cron.py 1970-01-01 00:00:00 +0000
77+++ cron_watcher/cron.py 2014-05-15 07:16:29 +0000
78@@ -0,0 +1,65 @@
79+# -*- coding: utf-8 -*-
80+##############################################################################
81+#
82+# OpenERP, Open Source Management Solution
83+# Copyright (c) 2010-2014 Elico Corp. All Rights Reserved.
84+# Augustin Cisterne-Kaas <augustin.cisterne-kaas@elico-corp.com>
85+#
86+# This program is free software: you can redistribute it and/or modify
87+# it under the terms of the GNU Affero General Public License as
88+# published by the Free Software Foundation, either version 3 of the
89+# License, or (at your option) any later version.
90+#
91+# This program is distributed in the hope that it will be useful,
92+# but WITHOUT ANY WARRANTY; without even the implied warranty of
93+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
94+# GNU Affero General Public License for more details.
95+#
96+# You should have received a copy of the GNU Affero General Public License
97+# along with this program. If not, see <http://www.gnu.org/licenses/>.
98+#
99+##############################################################################
100+from openerp.osv import orm
101+import time
102+from datetime import datetime
103+from openerp.tools.translate import _
104+
105+
106+class ir_cron(orm.Model):
107+ _inherit = 'ir.cron'
108+
109+ def _scheduler_cron_watcher(self, cr, uid, interval,
110+ domain=None, context=None):
111+ interval *= 60
112+ m = self.pool.get('ir.model.data')
113+ cron_ids = self.search(cr, uid, [], context=context)
114+ date_format = "%Y-%m-%d %H:%M:%S"
115+ current_date = time.strftime(date_format)
116+ current_date = datetime.strptime(current_date, date_format)
117+ message_pool = self.pool.get('mail.message')
118+
119+ group = m.get_object(
120+ cr, uid, 'cron_watcher', 'res_groups_cron_watcher')
121+ admin_user = m.get_object(
122+ cr, uid, 'base', 'user_root')
123+ partner_ids = [(4, user.partner_id.id) for user in group.users]
124+ for cron in self.browse(cr, uid, cron_ids, context=context):
125+ if not cron.nextcall:
126+ continue
127+ cron_date = datetime.strptime(cron.nextcall, date_format)
128+ delay = (current_date - cron_date).total_seconds()
129+ delay_minutes = round(int(delay) / 60)
130+ email = {
131+ 'type': 'notification',
132+ 'author_id': admin_user.partner_id.id,
133+ 'partner_ids': partner_ids,
134+ 'notified_partner_ids': partner_ids,
135+ 'model': 'ir.cron',
136+ 'res_id': cron.id,
137+ 'subject': _('Cron Watcher Alert (%s)') % cron.name,
138+ 'body': _(
139+ 'The cron job named "%s" has been delayed for\
140+ more than %s minutes') % (cron.name, delay_minutes)
141+ }
142+ if delay > interval:
143+ message_pool.create(cr, uid, email, context=context)
144
145=== added file 'cron_watcher/cron_data.xml'
146--- cron_watcher/cron_data.xml 1970-01-01 00:00:00 +0000
147+++ cron_watcher/cron_data.xml 2014-05-15 07:16:29 +0000
148@@ -0,0 +1,22 @@
149+<?xml version="1.0" encoding="utf-8"?>
150+<openerp>
151+ <data noupdate="1">
152+ <record forcecreate="True" id="ir_cron_watcher" model="ir.cron">
153+ <field name="name">Cron Watcher</field>
154+ <field eval="True" name="active"/>
155+ <field name="user_id" ref="base.user_root"/>
156+ <field name="interval_number">1</field>
157+ <field name="interval_type">hours</field>
158+ <field name="numbercall">-1</field>
159+ <field eval="False" name="doall"/>
160+ <field eval="'ir.cron'" name="model"/>
161+ <field eval="'_scheduler_cron_watcher'" name="function"/>
162+ <field eval="'(15,)'" name="args"/>
163+ </record>
164+ <record forcecreate="True" id="res_groups_cron_watcher" model="res.groups">
165+ <field name="name">Cron Watcher</field>
166+ <field eval="True" name="active"/>
167+ <field name="users" eval="[(4, ref('base.user_root'))]" />
168+ </record>
169+ </data>
170+</openerp>
171\ No newline at end of file