File size: 3,753 Bytes
079c32c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
from typing import Optional, Any, Mapping
from ..base import ResponsibleException
from ..exception import SlaveErrorCode
class ConnectionRefuse(ResponsibleException):
"""
Overview:
Exception represents the refuse to connection to slave from master, can be used in method `_before_connection`.
Example:
- Without data
>>> raise ConnectionRefuse
- With refuse data
>>> raise ConnectionRefuse({'data': 233})
"""
def __init__(self, data: Optional[Mapping[str, Any]] = None):
"""
Overview:
Constructor of ConnectionRefuse
Arguments:
- data (:obj:`Optional[Mapping[str, Any]]`): Key-value-formed refuse data
"""
ResponsibleException.__init__(
self,
SlaveErrorCode.SLAVE_CONNECTION_REFUSED,
message='Connection refused!',
data=data or {},
status_code=403,
)
class DisconnectionRefuse(ResponsibleException):
"""
Overview:
Exception represents the refuse to disconnection to slave from master,
can be used in method `_before_disconnection`.
Example:
- Without data
>>> raise DisconnectionRefuse
- With refuse data
>>> raise DisconnectionRefuse({'data': 233})
"""
def __init__(self, data: Optional[Mapping[str, Any]] = None):
"""
Overview:
Constructor of DisconnectionRefuse
Arguments:
- data (:obj:`Optional[Mapping[str, Any]]`): Key-value-formed refuse data
"""
ResponsibleException.__init__(
self,
SlaveErrorCode.SLAVE_DISCONNECTION_REFUSED,
message='Disconnection refused!',
data=data or {},
status_code=403,
)
class TaskRefuse(ResponsibleException):
"""
Overview:
Exception represents the refuse to tasks, can be used in method `_before_task`.
Example:
- Without data
>>> raise TaskRefuse
- With refuse data
>>> raise TaskRefuse({'data': 233})
"""
def __init__(self, data: Optional[Mapping[str, Any]] = None):
"""
Overview:
Constructor of TaskRefuse
Arguments:
- data (:obj:`Optional[Mapping[str, Any]]`): Key-value-formed refuse data
"""
ResponsibleException.__init__(
self,
SlaveErrorCode.TASK_REFUSED,
message='Task refused!',
data=data or {},
status_code=403,
)
class TaskFail(Exception):
"""
Overview:
Exception represents the failure of tasks, can be used in method `_process_task`.
Example:
- Without data
>>> raise TaskFail
- With failure data
>>> raise TaskFail({'data': 233})
- With both data and message
>>> raise TaskFail({'data': 233}, 'this is message')
"""
def __init__(self, result: Optional[Mapping[str, Any]] = None, message: Optional[str] = None):
"""
Overview:
Constructor of TaskFail
Arguments:
- result (:obj:`Optional[Mapping[str, Any]]`): Result of task failure
- message (:obj:`Optional[str]`): Message of task failure
"""
if message:
Exception.__init__(self, 'Task process failed - {message}.'.format(message=message))
else:
Exception.__init__(self, 'Task process failed.')
self.__result = result or {}
@property
def result(self) -> Mapping[str, Any]:
"""
Overview:
Get the result of task failure.
Returns:
Result of task failure.
"""
return self.__result
|