forked from OCA/server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathir_cron.py
76 lines (61 loc) · 2.74 KB
/
ir_cron.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- encoding: utf-8 -*-
##############################################################################
#
# Scheduler Error Mailer module for OpenERP
# Copyright (C) 2012-2013 Akretion (http://www.akretion.com/)
# @author: Sébastien Beau <[email protected]>
# @author David Beal <[email protected]>
# @author Alexis de Lattre <[email protected]>
#
# 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 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_id': fields.many2one(
'email.template',
'Error E-mail Template',
oldname="email_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_id:
# 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.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)