|
1 | | -class TaskiqError(Exception): |
| 1 | +from typing import Optional |
| 2 | + |
| 3 | +from izulu import root |
| 4 | + |
| 5 | + |
| 6 | +class TaskiqError(root.Error): |
2 | 7 | """Base exception for all errors.""" |
3 | 8 |
|
| 9 | + __template__ = "Exception occurred" |
| 10 | + |
4 | 11 |
|
5 | 12 | class TaskiqResultTimeoutError(TaskiqError): |
6 | 13 | """Waiting for task results has timed out.""" |
7 | 14 |
|
| 15 | + __template__ = "Waiting for task results has timed out, timeout={timeout}" |
| 16 | + timeout: Optional[float] = None |
| 17 | + |
8 | 18 |
|
9 | 19 | class BrokerError(TaskiqError): |
10 | 20 | """Base class for all broker errors.""" |
11 | 21 |
|
| 22 | + __template__ = "Base exception for all broker errors" |
| 23 | + |
| 24 | + |
| 25 | +class ListenError(TaskiqError): |
| 26 | + """Error if the broker is unable to listen to the queue.""" |
| 27 | + |
| 28 | + |
| 29 | +class SharedBrokerListenError(ListenError): |
| 30 | + """Error when someone tries to listen to the queue with shared broker.""" |
| 31 | + |
| 32 | + __template__ = "Shared broker cannot listen" |
| 33 | + |
12 | 34 |
|
13 | 35 | class SendTaskError(BrokerError): |
14 | 36 | """Error if the broker was unable to send the task to the queue.""" |
15 | 37 |
|
| 38 | + __template__ = "Cannot send task to the queue" |
| 39 | + |
| 40 | + |
| 41 | +class SharedBrokerSendTaskError(SendTaskError): |
| 42 | + """Error when someone tries to send task with shared broker.""" |
| 43 | + |
| 44 | + __template__ = ( |
| 45 | + "You cannot use kiq directly on shared task " |
| 46 | + "without setting the default_broker." |
| 47 | + ) |
| 48 | + |
| 49 | + |
| 50 | +class UnknownTaskError(SendTaskError): |
| 51 | + """Error if task is unknown.""" |
| 52 | + |
| 53 | + __template__ = "Cannot send unknown task to the queue, task name - {task_name}" |
| 54 | + task_name: str |
| 55 | + |
16 | 56 |
|
17 | 57 | class ResultBackendError(TaskiqError): |
18 | 58 | """Base class for all ResultBackend errors.""" |
19 | 59 |
|
| 60 | + __template__ = "Base exception for all result backend errors" |
| 61 | + |
20 | 62 |
|
21 | 63 | class ResultGetError(ResultBackendError): |
22 | 64 | """Error if ResultBackend was unable to get result.""" |
23 | 65 |
|
| 66 | + __template__ = "Cannot get result for the task" |
| 67 | + |
24 | 68 |
|
25 | 69 | class ResultSetError(ResultBackendError): |
26 | 70 | """Error if ResultBackend was unable to set result.""" |
27 | 71 |
|
| 72 | + __template__ = "Cannot set result for the task" |
| 73 | + |
28 | 74 |
|
29 | 75 | class ResultIsReadyError(ResultBackendError): |
30 | 76 | """Error if ResultBackend was unable to find out if the task is ready.""" |
31 | 77 |
|
| 78 | + __template__ = "Cannot find out if the task is ready" |
| 79 | + |
32 | 80 |
|
33 | 81 | class SecurityError(TaskiqError): |
34 | 82 | """Security related exception.""" |
35 | 83 |
|
| 84 | + __template__ = "Security exception occurred: {description}" |
| 85 | + description: str |
| 86 | + |
36 | 87 |
|
37 | 88 | class NoResultError(TaskiqError): |
38 | 89 | """Error if user does not want to set result.""" |
39 | 90 |
|
| 91 | + __template__ = "User doesn't want to set result" |
| 92 | + |
40 | 93 |
|
41 | 94 | class TaskRejectedError(TaskiqError): |
42 | 95 | """Task was rejected.""" |
43 | 96 |
|
| 97 | + __template__ = "Task was rejected" |
| 98 | + |
44 | 99 |
|
45 | 100 | class ScheduledTaskCancelledError(TaskiqError): |
46 | 101 | """Scheduled task was cancelled and not sent to the queue.""" |
| 102 | + |
| 103 | + __template__ = "Cannot send scheduled task to the queue." |
0 commit comments