From 8e46a7a61881e90e384bd3e9d77fc5c097b579d5 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Tue, 10 Feb 2026 09:55:57 +0100 Subject: [PATCH] Add TaskTimeoutException --- pulpcore/exceptions/base.py | 13 +++++++++++++ pulpcore/tasking/tasks.py | 7 ++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pulpcore/exceptions/base.py b/pulpcore/exceptions/base.py index 82398c5472..e607853d37 100644 --- a/pulpcore/exceptions/base.py +++ b/pulpcore/exceptions/base.py @@ -323,3 +323,16 @@ class ReplicateError(PulpException): def __str__(self): return f"[{self.error_code}] " + _("Replication failed") + + +class TaskTimeoutError(PulpException): + """ + Raised when an immediate task took too long. + """ + + error_code = "PLP0019" + + def __str__(self, task, timeout): + return f"[{self.error_code}] " + _( + "Immediate task {task} timed out after {timeout} seconds." + ).format(task=task, timeout=timeout) diff --git a/pulpcore/tasking/tasks.py b/pulpcore/tasking/tasks.py index eb270250c7..5c8a9c96fe 100644 --- a/pulpcore/tasking/tasks.py +++ b/pulpcore/tasking/tasks.py @@ -30,7 +30,7 @@ TASK_WAKEUP_HANDLE, TASK_WAKEUP_UNBLOCK, ) -from pulpcore.exceptions.base import PulpException, InternalErrorException +from pulpcore.exceptions.base import PulpException, InternalErrorException, TaskTimeoutError from pulp_glue.common.exceptions import PulpException as PulpGlueException from pulpcore.middleware import x_task_diagnostics_var @@ -223,10 +223,7 @@ async def _wrapper(): try: return await asyncio.wait_for(coro_fn(), timeout=IMMEDIATE_TIMEOUT) except asyncio.TimeoutError: - msg_template = "Immediate task %s timed out after %s seconds." - error_msg = msg_template % (task_pk, IMMEDIATE_TIMEOUT) - _logger.info(error_msg) - raise RuntimeError(error_msg) + raise TaskTimeoutError(task_pk, timeout=IMMEDIATE_TIMEOUT) return _wrapper