Skip to content

ding.interaction.slave.action

ding.interaction.slave.action

ConnectionRefuse

Bases: 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})

__init__(data=None)

Overview

Constructor of ConnectionRefuse

Arguments: - data (:obj:Optional[Mapping[str, Any]]): Key-value-formed refuse data

DisconnectionRefuse

Bases: 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})

__init__(data=None)

Overview

Constructor of DisconnectionRefuse

Arguments: - data (:obj:Optional[Mapping[str, Any]]): Key-value-formed refuse data

TaskRefuse

Bases: 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})

__init__(data=None)

Overview

Constructor of TaskRefuse

Arguments: - data (:obj:Optional[Mapping[str, Any]]): Key-value-formed refuse data

TaskFail

Bases: 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')

result property

Overview

Get the result of task failure.

Returns: Result of task failure.

__init__(result=None, message=None)

Overview

Constructor of TaskFail

Arguments: - result (:obj:Optional[Mapping[str, Any]]): Result of task failure - message (:obj:Optional[str]): Message of task failure

Full Source Code

../ding/interaction/slave/action.py

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