Skip to content

Commit f4c03bc

Browse files
committed
Added new base class for exceptions, added templates
Signed-off-by: chandr-andr (Kiselev Aleksandr) <[email protected]>
1 parent ad114ce commit f4c03bc

File tree

6 files changed

+13
-8
lines changed

6 files changed

+13
-8
lines changed

taskiq/brokers/inmemory_broker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async def kick(self, message: BrokerMessage) -> None:
156156
"""
157157
target_task = self.find_task(message.task_name)
158158
if target_task is None:
159-
raise TaskiqError("Unknown task.")
159+
raise TaskiqError(description="Unknown task.")
160160

161161
receiver_cb = self.receiver.callback(message=message.message)
162162
if self.await_inplace:

taskiq/brokers/shared_broker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ async def kick(self, message: BrokerMessage) -> None:
5757
:raises TaskiqError: if called.
5858
"""
5959
raise TaskiqError(
60-
"You cannot use kiq directly on shared task "
61-
"without setting the default_broker.",
60+
description=(
61+
"You cannot use kiq directly on shared task "
62+
"without setting the default_broker."
63+
),
6264
)
6365

6466
async def listen(self) -> AsyncGenerator[bytes, None]: # type: ignore
@@ -69,7 +71,7 @@ async def listen(self) -> AsyncGenerator[bytes, None]: # type: ignore
6971
7072
:raises TaskiqError: if called.
7173
"""
72-
raise TaskiqError("Shared broker cannot listen")
74+
raise TaskiqError(description="Shared broker cannot listen")
7375

7476
def _register_task(
7577
self,

taskiq/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
class TaskiqError(root.Error):
55
"""Base exception for all errors."""
66

7-
__template__ = "Base exception for all errors"
7+
__template__ = "Exception occurred: {description}"
8+
description: str
89

910

1011
class TaskiqResultTimeoutError(TaskiqError):

taskiq/funcs.py

Lines changed: 1 addition & 1 deletion
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", timeout=timeout)
50+
raise TaskiqResultTimeoutError(timeout=timeout)
5151
check_tasks = []
5252
for task in tasks:
5353
check_tasks.append(loop.create_task(check_task(task)))

taskiq/receiver/receiver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ async def prefetcher(
353353
"""
354354
fetched_tasks: int = 0
355355
iterator = self.broker.listen()
356-
current_message: asyncio.Task[bytes | AckableMessage] = asyncio.create_task(
356+
current_message: asyncio.Task[
357+
Union[bytes, AckableMessage]
358+
] = asyncio.create_task(
357359
iterator.__anext__(), # type: ignore
358360
)
359361

taskiq/task.py

Lines changed: 1 addition & 1 deletion
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("Timed out", timeout=timeout)
154+
raise TaskiqResultTimeoutError(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)