diff --git a/scheduler_error_mailer/README.rst b/scheduler_error_mailer/README.rst
index 16b0dea51f2..a58bf1e90a5 100644
--- a/scheduler_error_mailer/README.rst
+++ b/scheduler_error_mailer/README.rst
@@ -1,3 +1,7 @@
+.. image:: https://odoo-community.org/readme-banner-image
+ :target: https://odoo-community.org/get-involved?utm_source=readme
+ :alt: Odoo Community Association
+
======================
Scheduler Error Mailer
======================
@@ -13,7 +17,7 @@ Scheduler Error Mailer
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
-.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
+.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
@@ -43,6 +47,7 @@ To configure this module, you need to:
#. Go to Settings -> Technical -> Automation -> Scheduled Actions
#. Choose the scheduled Actions you want to send the error email and select the E-mail Template in the Error E-mail Template field.
+#. Optionally set the Email Retries field to the number of consecutive failures allowed before the error email is sent (1 by default, i.e. the email is sent on the first failure).
Bug Tracker
===========
diff --git a/scheduler_error_mailer/__manifest__.py b/scheduler_error_mailer/__manifest__.py
index 8d12c8894c0..96bdf20a145 100644
--- a/scheduler_error_mailer/__manifest__.py
+++ b/scheduler_error_mailer/__manifest__.py
@@ -6,7 +6,7 @@
{
"name": "Scheduler Error Mailer",
- "version": "16.0.1.0.0",
+ "version": "16.0.1.0.1",
"category": "Extra Tools",
"license": "AGPL-3",
"author": "Akretion,Sodexis,Odoo Community Association (OCA)",
diff --git a/scheduler_error_mailer/models/__init__.py b/scheduler_error_mailer/models/__init__.py
index b365c0e973b..6a099d23e8b 100644
--- a/scheduler_error_mailer/models/__init__.py
+++ b/scheduler_error_mailer/models/__init__.py
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+from . import ir_actions_server
from . import ir_cron
diff --git a/scheduler_error_mailer/models/ir_actions_server.py b/scheduler_error_mailer/models/ir_actions_server.py
new file mode 100644
index 00000000000..b5f78137a2e
--- /dev/null
+++ b/scheduler_error_mailer/models/ir_actions_server.py
@@ -0,0 +1,13 @@
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import fields, models
+
+
+class IrActionsServer(models.Model):
+ _inherit = "ir.actions.server"
+
+ failure_count = fields.Integer(
+ default=0,
+ readonly=True,
+ help="Number of consecutive failures of the related scheduled action.",
+ )
diff --git a/scheduler_error_mailer/models/ir_cron.py b/scheduler_error_mailer/models/ir_cron.py
index 7bb8f6c70bd..b950dfff763 100644
--- a/scheduler_error_mailer/models/ir_cron.py
+++ b/scheduler_error_mailer/models/ir_cron.py
@@ -24,6 +24,23 @@ class IrCron(models.Model):
"scheduler_error_mailer.scheduler_error_mailer", False
),
)
+ email_retries = fields.Integer(
+ default=1,
+ help="Number of consecutive failures allowed "
+ "before the error email is sent.",
+ )
+
+ @api.model
+ def _callback(self, cron_name, server_action_id, job_id):
+ # failure_count is stored on the delegated ir.actions.server row:
+ # the scheduler locks the ir_cron row while the job runs, so the
+ # cron record itself cannot be written from within the job
+ action = self.env["ir.actions.server"].sudo().browse(server_action_id)
+ failures_before = action.failure_count
+ res = super()._callback(cron_name, server_action_id, job_id)
+ if failures_before and action.failure_count == failures_before:
+ action.failure_count = 0
+ return res
@api.model
def _handle_callback_exception(
@@ -35,6 +52,12 @@ def _handle_callback_exception(
my_cron = self.browse(job_id)
if my_cron.email_template_id:
+ action = my_cron.ir_actions_server_id.sudo()
+ action.failure_count += 1
+ if action.failure_count < my_cron.email_retries:
+ return res
+ action.failure_count = 0
+
# we put the job_exception in context to be able to print it inside
# the email template
context = {"job_exception": str(job_exception), "dbname": self._cr.dbname}
diff --git a/scheduler_error_mailer/readme/CONFIGURE.rst b/scheduler_error_mailer/readme/CONFIGURE.rst
index baf4c1a6da0..902da70c00d 100644
--- a/scheduler_error_mailer/readme/CONFIGURE.rst
+++ b/scheduler_error_mailer/readme/CONFIGURE.rst
@@ -2,3 +2,4 @@ To configure this module, you need to:
#. Go to Settings -> Technical -> Automation -> Scheduled Actions
#. Choose the scheduled Actions you want to send the error email and select the E-mail Template in the Error E-mail Template field.
+#. Optionally set the Email Retries field to the number of consecutive failures allowed before the error email is sent (1 by default, i.e. the email is sent on the first failure).
diff --git a/scheduler_error_mailer/static/description/index.html b/scheduler_error_mailer/static/description/index.html
index cc2d1ffd560..de3c0296029 100644
--- a/scheduler_error_mailer/static/description/index.html
+++ b/scheduler_error_mailer/static/description/index.html
@@ -1,18 +1,18 @@
-
-Scheduler Error Mailer
+README.rst
-
-
Scheduler Error Mailer
+
+
+
+
+
+
+
Scheduler Error Mailer
-

+

This module adds the possibility to send an e-mail when a scheduler raises
an error.
Table of contents
@@ -386,15 +391,16 @@
Scheduler Error Mailer
-
+
To configure this module, you need to:
- Go to Settings -> Technical -> Automation -> Scheduled Actions
- Choose the scheduled Actions you want to send the error email and select the E-mail Template in the Error E-mail Template field.
+- Optionally set the Email Retries field to the number of consecutive failures allowed before the error email is sent (1 by default, i.e. the email is sent on the first failure).
-
+
Bugs are tracked on GitHub Issues.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
@@ -402,16 +408,16 @@
Do not contact contributors directly about support or help with technical issues.
-
+
-
+
This module is maintained by the OCA.
-

+
+
+
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
@@ -437,5 +445,6 @@
+
diff --git a/scheduler_error_mailer/tests/test_scheduler_error_mailer.py b/scheduler_error_mailer/tests/test_scheduler_error_mailer.py
index 7f26a41f2d8..59029393e03 100644
--- a/scheduler_error_mailer/tests/test_scheduler_error_mailer.py
+++ b/scheduler_error_mailer/tests/test_scheduler_error_mailer.py
@@ -24,6 +24,30 @@ def test_error_cron(self):
Exception("hello world"),
)
+ def test_error_cron_retries(self):
+ action = self.cron.ir_actions_server_id
+ action.failure_count = 0
+ self.cron.email_retries = 2
+ with patch.object(self.env.cr, "rollback"), patch.object(
+ self.registry["mail.template"], "send_mail"
+ ) as send_mail:
+ self.env["ir.cron"]._handle_callback_exception(
+ self.cron.name,
+ action.id,
+ self.cron.id,
+ Exception("hello world"),
+ )
+ send_mail.assert_not_called()
+ self.assertEqual(action.failure_count, 1)
+ self.env["ir.cron"]._handle_callback_exception(
+ self.cron.name,
+ action.id,
+ self.cron.id,
+ Exception("hello world"),
+ )
+ send_mail.assert_called_once()
+ self.assertEqual(action.failure_count, 0)
+
def test_init_hook(self):
post_init_hook(self.env.cr, self.env.registry)
self.assertFalse(
diff --git a/scheduler_error_mailer/views/ir_cron.xml b/scheduler_error_mailer/views/ir_cron.xml
index d22099c7427..a86ec3e0ac1 100644
--- a/scheduler_error_mailer/views/ir_cron.xml
+++ b/scheduler_error_mailer/views/ir_cron.xml
@@ -14,6 +14,14 @@
+
+