Skip to content

Commit 97ee677

Browse files
committed
Added new base class for exceptions, added templates
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
1 parent fec9633 commit 97ee677

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

poetry.lock

+13-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pytz = "*"
4747
orjson = { version = "^3", optional = true }
4848
msgpack = { version = "^1.0.7", optional = true }
4949
cbor2 = { version = "^5", optional = true }
50+
izulu = "^0.5.3"
5051

5152
[tool.poetry.dev-dependencies]
5253
pytest = "^7.1.2"

taskiq/exceptions.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,59 @@
1-
class TaskiqError(Exception):
1+
from izulu import root
2+
3+
class TaskiqError(root.Error):
24
"""Base exception for all errors."""
35

6+
__template__ = "Base exception for all errors"
7+
48

59
class TaskiqResultTimeoutError(TaskiqError):
610
"""Waiting for task results has timed out."""
711

12+
__template__ = "Waiting for task results has timed out, timeout={timeout}"
13+
timeout: float
14+
815

916
class BrokerError(TaskiqError):
1017
"""Base class for all broker errors."""
1118

19+
__template__ = "Base exception for all broker errors"
20+
1221

1322
class SendTaskError(BrokerError):
1423
"""Error if the broker was unable to send the task to the queue."""
1524

25+
__template__ = "Cannot send task to the queue"
26+
1627

1728
class ResultBackendError(TaskiqError):
1829
"""Base class for all ResultBackend errors."""
1930

31+
__template__ = "Base exception for all result backend errors"
32+
2033

2134
class ResultGetError(ResultBackendError):
2235
"""Error if ResultBackend was unable to get result."""
2336

37+
__template__ = "Cannot get result for the task"
38+
2439

2540
class ResultSetError(ResultBackendError):
2641
"""Error if ResultBackend was unable to set result."""
2742

43+
__template__ = "Cannot set result for the task"
44+
2845

2946
class ResultIsReadyError(ResultBackendError):
3047
"""Error if ResultBackend was unable to find out if the task is ready."""
3148

49+
__template__ = "Cannot find out if the task is ready"
50+
3251

3352
class SecurityError(TaskiqError):
3453
"""Security related exception."""
3554

55+
__template__ = "Base exception for all security errors"
56+
3657

3758
class NoResultError(TaskiqError):
3859
"""Error if user does not want to set result."""
@@ -41,6 +62,10 @@ class NoResultError(TaskiqError):
4162
class TaskRejectedError(TaskiqError):
4263
"""Task was rejected."""
4364

65+
__template__ = "Task was rejected"
66+
4467

4568
class ScheduledTaskCancelledError(TaskiqError):
4669
"""Scheduled task was cancelled and not sent to the queue."""
70+
71+
__template__ = "Cannot send scheduled task to the queue."

taskiq/funcs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async def check_task(task: AsyncTaskiqTask[Any]) -> None:
4747

4848
while task_ids:
4949
if 0 < timeout < time() - start_time:
50-
raise TaskiqResultTimeoutError("Timed out")
50+
raise TaskiqResultTimeoutError("Timed out", timeout=timeout)
5151
check_tasks = []
5252
for task in tasks:
5353
check_tasks.append(loop.create_task(check_task(task)))

taskiq/task.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ async def wait_result(
151151
while not await self.is_ready():
152152
await asyncio.sleep(check_interval)
153153
if 0 < timeout < time() - start_time:
154-
raise TaskiqResultTimeoutError
154+
raise TaskiqResultTimeoutError("Timed out", timeout=timeout)
155155
return await self.get_result(with_logs=with_logs)
156156

157157
async def get_progress(self) -> "Optional[TaskProgress[Any]]":

0 commit comments

Comments
 (0)