Skip to content

Commit aff9ae1

Browse files
committed
[UPD] base_bg: Update error handling to accept string type and improve timeout notification
closes #329 Signed-off-by: Nicolas Mac Rouillon (ADV) <nmr@adhoc.inc>
1 parent 80131ad commit aff9ae1

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

base_bg/models/bg_job.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def run(self):
180180
self._handle_job_error(e)
181181
raise
182182

183-
def _handle_job_error(self, error: Exception):
183+
def _handle_job_error(self, error: Exception | str):
184184
"""
185185
Handle job execution error
186186
@@ -265,6 +265,7 @@ def _cron_check_running_jobs(self):
265265
]
266266
)
267267
for job in jobs:
268-
job.write({"state": "failed", "error_message": _("Job timed out")})
269-
message = _("Job %s timed out") % job.name
270-
job._notify_user(message)
268+
job._handle_job_error(_("Job timed out"))
269+
if job.state == "failed":
270+
message = _("Job %s timed out") % job.name
271+
job._notify_user(message)

base_bg/tests/test_bg_job.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ def test_cron_check_running_jobs(self):
7777
"""Test cron method for checking timed out running jobs."""
7878
# Create a job that appears to be running for too long
7979
old_time = fields.Datetime.now() - timedelta(hours=6)
80-
job = self._create_job(name="Timed Out Job", state="running", start_time=old_time)
80+
job = self._create_job(name="Timed Out Job", state="running", start_time=old_time, max_retries=1)
8181

8282
# Run the cron method
8383
self._set_cron_timeout(300)
84-
self.BgJob._cron_check_running_jobs()
84+
with patch("odoo.addons.base_bg.models.bg_job._logger.error"):
85+
self.BgJob._cron_check_running_jobs()
8586

8687
# Refresh the job from database
8788
job = self.BgJob.browse(job.id)

0 commit comments

Comments
 (0)