diff --git a/scheduler_error_mailer/__init__.py b/scheduler_error_mailer/__init__.py new file mode 100644 index 000000000..36504c54b --- /dev/null +++ b/scheduler_error_mailer/__init__.py @@ -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 +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +from . import ir_cron diff --git a/scheduler_error_mailer/__openerp__.py b/scheduler_error_mailer/__openerp__.py new file mode 100644 index 000000000..d8dd3eb36 --- /dev/null +++ b/scheduler_error_mailer/__openerp__.py @@ -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 +# @author David Beal +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + + +{ + 'name': 'Scheduler Error Mailer', + 'summary': 'Send an e-mail when a scheduler fails', + 'version': '8.0.1.0.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,Odoo Community Association (OCA)", + '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, +} diff --git a/scheduler_error_mailer/i18n/scheduler_error_mailer.pot b/scheduler_error_mailer/i18n/scheduler_error_mailer.pot new file mode 100644 index 000000000..95fe5ca84 --- /dev/null +++ b/scheduler_error_mailer/i18n/scheduler_error_mailer.pot @@ -0,0 +1,76 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * scheduler_error_mailer +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0rc1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2014-09-18 11:55+0000\n" +"PO-Revision-Date: 2014-09-18 11:55+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: scheduler_error_mailer +#: model:email.template,body_html:scheduler_error_mailer.scheduler_error_mailer +msgid "\n" +"
\n" +"\n" +"

OpenERP tried to run the scheduler ${object.name or ''} in the database ${ctx.get('dbname')} but it failed. Here is the error message :

\n" +"\n" +"\n" +"${ctx.get('job_exception') and ctx.get('job_exception').value or 'Failed to get the error message from the context.'}\n" +"\n" +"\n" +"

You may check the logs of the OpenERP server to get more information about this failure.

\n" +"\n" +"

Properties of the scheduler ${object.name or ''} :

\n" +"
    \n" +"
  • Model : ${object.model or ''}
  • \n" +"
  • Method : ${object.function or ''}
  • \n" +"
  • Arguments : ${object.args or ''}
  • \n" +"
  • Interval : ${object.interval_number or '0'} ${object.interval_type or ''}
  • \n" +"
  • Number of calls : ${object.numbercall or '0'}
  • \n" +"
  • Repeat missed : ${object.doall}
  • \n" +"
  • User : ${object.user_id.name or ''}
  • \n" +"
\n" +"\n" +"

\n" +"--
\n" +"Automatic e-mail sent by OpenERP. Do not reply.
\n" +"Database : ${ctx.get('dbname')}\n" +"

\n" +"
\n" +" " +msgstr "" + +#. module: scheduler_error_mailer +#: code:addons/scheduler_error_mailer/ir_cron.py:74 +#, python-format +msgid "Error :" +msgstr "" + +#. module: scheduler_error_mailer +#: field:ir.cron,email_template:0 +msgid "Error E-mail Template" +msgstr "" + +#. module: scheduler_error_mailer +#: help:ir.cron,email_template:0 +msgid "Select the email template that will be sent when this scheduler fails." +msgstr "" + +#. module: scheduler_error_mailer +#: code:addons/scheduler_error_mailer/ir_cron.py:75 +#, python-format +msgid "Task failure with UID = %d." +msgstr "" + +#. module: scheduler_error_mailer +#: model:email.template,subject:scheduler_error_mailer.scheduler_error_mailer +msgid "[DB ${ctx.get('dbname')}] Scheduler '${object.name or ''}' FAILED" +msgstr "" diff --git a/scheduler_error_mailer/images/scheduler_error_mailer.jpg b/scheduler_error_mailer/images/scheduler_error_mailer.jpg new file mode 100644 index 000000000..a8a3af766 Binary files /dev/null and b/scheduler_error_mailer/images/scheduler_error_mailer.jpg differ diff --git a/scheduler_error_mailer/ir_cron.py b/scheduler_error_mailer/ir_cron.py new file mode 100644 index 000000000..17b0f2c30 --- /dev/null +++ b/scheduler_error_mailer/ir_cron.py @@ -0,0 +1,75 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Scheduler Error Mailer module for OpenERP +# Copyright (C) 2012-2013 Akretion (http://www.akretion.com/) +# @author: Sébastien Beau +# @author David Beal +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +from openerp import SUPERUSER_ID +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, + 'dbname': cr.dbname, + } + + _logger.debug("Sending scheduler error email with context=%s", + context) + + self.pool['email.template'].send_mail( + cr, SUPERUSER_ID, my_cron.email_template.id, my_cron.id, + force_send=True, context=context) + + return res + + 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) diff --git a/scheduler_error_mailer/ir_cron.xml b/scheduler_error_mailer/ir_cron.xml new file mode 100644 index 000000000..ee1bcfd6d --- /dev/null +++ b/scheduler_error_mailer/ir_cron.xml @@ -0,0 +1,24 @@ + + + + + + + + + ir.cron.error.mailer.form + ir.cron + + + + + + + + + + + diff --git a/scheduler_error_mailer/ir_cron_demo.xml b/scheduler_error_mailer/ir_cron_demo.xml new file mode 100644 index 000000000..4c6fc5e7b --- /dev/null +++ b/scheduler_error_mailer/ir_cron_demo.xml @@ -0,0 +1,26 @@ + + + + + + + + + Test Scheduler Error Mailer + + + 1 + hours + -1 + + + ir.cron + _test_scheduler_failure + + + + diff --git a/scheduler_error_mailer/ir_cron_email_tpl.xml b/scheduler_error_mailer/ir_cron_email_tpl.xml new file mode 100644 index 000000000..d0bd7859b --- /dev/null +++ b/scheduler_error_mailer/ir_cron_email_tpl.xml @@ -0,0 +1,50 @@ + + + + + + + + + Scheduler Error + ${object.user_id.user_email or ''} + ${object.user_id.user_email or ''} + [DB ${ctx.get('dbname')}] Scheduler '${object.name or ''}' FAILED + + + + +

OpenERP tried to run the scheduler ${object.name or ''} in the database ${ctx.get('dbname')} but it failed. Here is the error message :

+ + +${ctx.get('job_exception') and ctx.get('job_exception').value or 'Failed to get the error message from the context.'} + + +

You may check the logs of the OpenERP server to get more information about this failure.

+ +

Properties of the scheduler ${object.name or ''} :

+
    +
  • Model : ${object.model or ''}
  • +
  • Method : ${object.function or ''}
  • +
  • Arguments : ${object.args or ''}
  • +
  • Interval : ${object.interval_number or '0'} ${object.interval_type or ''}
  • +
  • Number of calls : ${object.numbercall or '0'}
  • +
  • Repeat missed : ${object.doall}
  • +
  • User : ${object.user_id.name or ''}
  • +
+ +

+--
+Automatic e-mail sent by OpenERP. Do not reply.
+Database : ${ctx.get('dbname')} +

+ + ]]>
+
+ +
+
diff --git a/scheduler_error_mailer/static/description/icon.png b/scheduler_error_mailer/static/description/icon.png new file mode 100644 index 000000000..6b22abf97 Binary files /dev/null and b/scheduler_error_mailer/static/description/icon.png differ