Skip to content

Commit

Permalink
Added new base class for exceptions, added templates
Browse files Browse the repository at this point in the history
Signed-off-by: chandr-andr (Kiselev Aleksandr) <chandr@chandr.net>
  • Loading branch information
chandr-andr committed Dec 22, 2024
1 parent fec9633 commit 97ee677
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
15 changes: 13 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pytz = "*"
orjson = { version = "^3", optional = true }
msgpack = { version = "^1.0.7", optional = true }
cbor2 = { version = "^5", optional = true }
izulu = "^0.5.3"

[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
Expand Down
27 changes: 26 additions & 1 deletion taskiq/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,59 @@
class TaskiqError(Exception):
from izulu import root

class TaskiqError(root.Error):
"""Base exception for all errors."""

__template__ = "Base exception for all errors"


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

__template__ = "Waiting for task results has timed out, timeout={timeout}"
timeout: float


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

__template__ = "Base exception for all broker errors"


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

__template__ = "Cannot send task to the queue"


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

__template__ = "Base exception for all result backend errors"


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

__template__ = "Cannot get result for the task"


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

__template__ = "Cannot set result for the task"


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

__template__ = "Cannot find out if the task is ready"


class SecurityError(TaskiqError):
"""Security related exception."""

__template__ = "Base exception for all security errors"


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

__template__ = "Task was rejected"


class ScheduledTaskCancelledError(TaskiqError):
"""Scheduled task was cancelled and not sent to the queue."""

__template__ = "Cannot send scheduled task to the queue."
2 changes: 1 addition & 1 deletion taskiq/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def check_task(task: AsyncTaskiqTask[Any]) -> None:

while task_ids:
if 0 < timeout < time() - start_time:
raise TaskiqResultTimeoutError("Timed out")
raise TaskiqResultTimeoutError("Timed out", timeout=timeout)
check_tasks = []
for task in tasks:
check_tasks.append(loop.create_task(check_task(task)))
Expand Down
2 changes: 1 addition & 1 deletion taskiq/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ async def wait_result(
while not await self.is_ready():
await asyncio.sleep(check_interval)
if 0 < timeout < time() - start_time:
raise TaskiqResultTimeoutError
raise TaskiqResultTimeoutError("Timed out", timeout=timeout)
return await self.get_result(with_logs=with_logs)

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

0 comments on commit 97ee677

Please sign in to comment.