openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #00214
[Merge] lp:~akretion-team/server-env-tools/70-scheduler-error-mailer into lp:server-env-tools
Alexis de Lattre has proposed merging lp:~akretion-team/server-env-tools/70-scheduler-error-mailer into lp:server-env-tools.
Requested reviews:
Server Environment And Tools Core Editors (server-env-tools-core-editors)
For more details, see:
https://code.launchpad.net/~akretion-team/server-env-tools/70-scheduler-error-mailer/+merge/188240
Propose to add the "scheduler_error_mailer" module to lp:server-env-tools.
This is a small and very usefull module that sends an email (from an email template) when a scheduler raises an error. We use it on almost all our openerp deployments.
--
https://code.launchpad.net/~akretion-team/server-env-tools/70-scheduler-error-mailer/+merge/188240
Your team Server Environment And Tools Core Editors is requested to review the proposed merge of lp:~akretion-team/server-env-tools/70-scheduler-error-mailer into lp:server-env-tools.
=== added directory 'scheduler_error_mailer'
=== added file 'scheduler_error_mailer/__init__.py'
--- scheduler_error_mailer/__init__.py 1970-01-01 00:00:00 +0000
+++ scheduler_error_mailer/__init__.py 2013-09-29 21:59:41 +0000
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Scheduler Error Mailer module for OpenERP
+# Copyright (C) 2012-2013 Akretion (http://www.akretion.com/)
+# @author: Sébastien Beau <sebastien.beau@xxxxxxxxxxxx>
+# @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import ir_cron
=== added file 'scheduler_error_mailer/__openerp__.py'
--- scheduler_error_mailer/__openerp__.py 1970-01-01 00:00:00 +0000
+++ scheduler_error_mailer/__openerp__.py 2013-09-29 21:59:41 +0000
@@ -0,0 +1,48 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# Scheduler Error Mailer module for OpenERP
+# Copyright (C) 2012-2013 Akretion (http://www.akretion.com/)
+# @author: Sébastien Beau <sebastien.beau@xxxxxxxxxxxx>
+# @author David Beal <bealdavid@xxxxxxxxx>
+# @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+
+{
+ 'name': 'Scheduler Error Mailer',
+ 'summary': 'Send an e-mail when a scheduler fails',
+ 'version': '1.0',
+ 'category': 'Extra Tools',
+ 'license': 'AGPL-3',
+ 'description': """
+Scheduler Error Mailer
+======================
+
+This module adds the possibility to send an e-mail when a scheduler raises an error.""",
+ 'author': 'Akretion',
+ 'website': 'http://www.akretion.com/',
+ 'depends': ['email_template'],
+ 'data': [
+ 'ir_cron.xml',
+ 'ir_cron_email_tpl.xml',
+ ],
+ 'demo': ['ir_cron_demo.xml'],
+ 'images': ['images/scheduler_error_mailer.jpg'],
+ 'installable': True,
+ 'active': False,
+}
=== added directory 'scheduler_error_mailer/images'
=== added file 'scheduler_error_mailer/images/scheduler_error_mailer.jpg'
Binary files scheduler_error_mailer/images/scheduler_error_mailer.jpg 1970-01-01 00:00:00 +0000 and scheduler_error_mailer/images/scheduler_error_mailer.jpg 2013-09-29 21:59:41 +0000 differ
=== added file 'scheduler_error_mailer/ir_cron.py'
--- scheduler_error_mailer/ir_cron.py 1970-01-01 00:00:00 +0000
+++ scheduler_error_mailer/ir_cron.py 2013-09-29 21:59:41 +0000
@@ -0,0 +1,66 @@
+# -*- encoding: utf-8 -*-
+#################################################################################
+#
+# Scheduler Error Mailer module for OpenERP
+# Copyright (C) 2012-2013 Akretion (http://www.akretion.com/)
+# @author: Sébastien Beau <sebastien.beau@xxxxxxxxxxxx>
+# @author David Beal <bealdavid@xxxxxxxxx>
+# @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.osv import orm, fields
+from openerp.tools.translate import _
+import logging
+
+logger = logging.getLogger(__name__)
+
+class ir_cron(orm.Model):
+ _inherit = "ir.cron"
+
+ _columns = {
+ 'email_template': fields.many2one('email.template',
+ 'Error E-mail Template',
+ help="Select the email template that will be sent when this scheduler fails."),
+ }
+
+
+ def _handle_callback_exception(self, cr, uid, model_name, method_name, args, job_id, job_exception):
+
+ res = super(ir_cron, self)._handle_callback_exception(cr, uid,
+ model_name, method_name, args, job_id, job_exception)
+
+ my_cron = self.browse(cr, uid, job_id)
+
+ if my_cron.email_template:
+ # we put the job_exception in context to be able to print it inside
+ # the email template
+ context = {'job_exception': job_exception}
+ logger.debug("Sending scheduler error email with context=%s" % context)
+ self.pool['email.template'].send_mail(cr, uid,
+ my_cron.email_template.id, my_cron.id, force_send=True,
+ context=context)
+
+ return res
+
+
+class res_users(orm.Model):
+ _inherit = 'res.users'
+
+ def test_scheduler_failure(self, cr, uid, context=None):
+ """This function is used to test and debug this module"""
+ raise orm.except_orm(_('Error :'), _("Task failure with UID = %d." % uid))
+
=== added file 'scheduler_error_mailer/ir_cron.xml'
--- scheduler_error_mailer/ir_cron.xml 1970-01-01 00:00:00 +0000
+++ scheduler_error_mailer/ir_cron.xml 2013-09-29 21:59:41 +0000
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2012-2013 Akretion (http://www.akretion.com/)
+ The licence is in the file __openerp__.py
+-->
+
+<openerp>
+<data>
+
+
+<record id="ir_cron_error_mailer_view" model="ir.ui.view">
+ <field name="name">ir.cron.error.mailer.form</field>
+ <field name="model">ir.cron</field>
+ <field name="inherit_id" ref="base.ir_cron_view"/>
+ <field name="arch" type="xml">
+ <field name="doall" position="after">
+ <field name="email_template" />
+ </field>
+ </field>
+</record>
+
+
+</data>
+</openerp>
=== added file 'scheduler_error_mailer/ir_cron_demo.xml'
--- scheduler_error_mailer/ir_cron_demo.xml 1970-01-01 00:00:00 +0000
+++ scheduler_error_mailer/ir_cron_demo.xml 2013-09-29 21:59:41 +0000
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ Copyright (C) 2013 Akretion (http://www.akretion.com/)
+ @author Alexis de Lattre <alexis.delattre@xxxxxxxxxxxx>
+ The licence is in the file __openerp__.py
+-->
+
+<openerp>
+<data noupdate="1">
+
+<record id="test_scheduler_error_mailer" model="ir.cron">
+ <field name="name">Test Scheduler Error Mailer</field>
+ <field name="active" eval="False"/>
+ <field name="user_id" ref="base.user_root"/>
+ <field name="interval_number">1</field>
+ <field name="interval_type">hours</field>
+ <field name="numbercall">-1</field> <!-- don't limit the number of calls -->
+ <field name="doall" eval="True"/>
+ <field name="email_template" ref="scheduler_error_mailer"/>
+ <field name="model" eval="'res.users'"/>
+ <field name="function" eval="'test_scheduler_failure'" />
+ <field name="args" eval="'()'"/>
+</record>
+
+</data>
+</openerp>
=== added file 'scheduler_error_mailer/ir_cron_email_tpl.xml'
--- scheduler_error_mailer/ir_cron_email_tpl.xml 1970-01-01 00:00:00 +0000
+++ scheduler_error_mailer/ir_cron_email_tpl.xml 2013-09-29 21:59:41 +0000
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2012-2013 Akretion (http://www.akretion.com/)
+ The licence is in the file __openerp__.py
+-->
+
+<openerp>
+<data noupdate="0">
+
+<!-- Error Email template -->
+<record id="scheduler_error_mailer" model="email.template">
+ <field name="name">Scheduler Error</field>
+ <field name="email_from">${object.user_id.user_email or ''}</field>
+ <field name="email_to">${object.user_id.user_email or ''}</field>
+ <field name="subject">Scheduler '${object.name or ''}' FAILED</field>
+ <field name="model_id" ref="base.model_ir_cron"/>
+ <field name="auto_delete" eval="True"/>
+ <field name="body_html"><![CDATA[
+<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
+
+<p>OpenERP tried to run the scheduler <em>${object.name or ''}</em> but it failed. Here is the error message :</p>
+
+<strong>
+${ctx.get('job_exception') and ctx.get('job_exception').value or 'Failed to get the error message from the context.'}
+</strong>
+
+<p>You may check the logs of the OpenERP server to get more information about this failure.</p>
+
+<p>Properties of the scheduler <em>${object.name or ''}</em> :</p>
+<ul>
+<li>Model : ${object.model or ''}</li>
+<li>Method : ${object.function or ''}</li>
+<li>Arguments : ${object.args or ''}</li>
+<li>Interval : ${object.interval_number or '0'} ${object.interval_type or ''}</li>
+<li>Number of calls : ${object.numbercall or '0'}</li>
+<li>Repeat missed : ${object.doall}</li>
+<li>User : ${object.user_id.name or ''}</li>
+</ul>
+
+<p>
+-- <br/>
+Automatic e-mail sent by OpenERP. Do not reply.
+</p>
+</div>
+ ]]></field>
+</record>
+<!-- TODO : print database name inside the email (we used object._cr.dbname in openerp 6.1, but it's not possible in OpenERP 7 because the executing of jinja2 is sandboxed and private attributes can't be accessed). -->
+
+</data>
+</openerp>
=== added directory 'scheduler_error_mailer/static'
=== added directory 'scheduler_error_mailer/static/src'
=== added directory 'scheduler_error_mailer/static/src/img'
=== added file 'scheduler_error_mailer/static/src/img/icon.png'
Binary files scheduler_error_mailer/static/src/img/icon.png 1970-01-01 00:00:00 +0000 and scheduler_error_mailer/static/src/img/icon.png 2013-09-29 21:59:41 +0000 differ
Follow ups