Skip to content

Commit 3477684

Browse files
committed
Add TaskTimeoutException
1 parent b1454fc commit 3477684

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

pulpcore/exceptions/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,16 @@ class ReplicateError(PulpException):
323323

324324
def __str__(self):
325325
return f"[{self.error_code}] " + _("Replication failed")
326+
327+
328+
class TaskTimeoutError(PulpException):
329+
"""
330+
Raised when an immediate task took too long.
331+
"""
332+
333+
error_code = "PLP0019"
334+
335+
def __str__(self, task, timeout):
336+
return f"[{self.error_code}] " + _(
337+
"Immediate task {task} timed out after {timeout} seconds."
338+
).format(task=task, timeout=timeout)

pulpcore/tasking/tasks.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
TASK_WAKEUP_HANDLE,
3131
TASK_WAKEUP_UNBLOCK,
3232
)
33-
from pulpcore.exceptions.base import PulpException, InternalErrorException
33+
from pulpcore.exceptions.base import PulpException, InternalErrorException, TaskTimeoutError
3434
from pulp_glue.common.exceptions import PulpException as PulpGlueException
3535

3636
from pulpcore.middleware import x_task_diagnostics_var
@@ -223,10 +223,7 @@ async def _wrapper():
223223
try:
224224
return await asyncio.wait_for(coro_fn(), timeout=IMMEDIATE_TIMEOUT)
225225
except asyncio.TimeoutError:
226-
msg_template = "Immediate task %s timed out after %s seconds."
227-
error_msg = msg_template % (task_pk, IMMEDIATE_TIMEOUT)
228-
_logger.info(error_msg)
229-
raise RuntimeError(error_msg)
226+
raise TaskTimeoutError(task, timeout=IMMEDIATE_TIMEOUT)
230227

231228
return _wrapper
232229

0 commit comments

Comments
 (0)