|
1 | | -import concurrent.futures |
2 | 1 | import datetime |
3 | 2 | import enum |
4 | 3 | from dataclasses import dataclass |
|
12 | 11 | from .._grpc.grpcwrapper.common_utils import IToProto |
13 | 12 |
|
14 | 13 |
|
15 | | -class Writer: |
16 | | - @property |
17 | | - def last_seqno(self) -> int: |
18 | | - raise NotImplementedError() |
19 | | - |
20 | | - def __init__(self, db: ydb.Driver): |
21 | | - pass |
22 | | - |
23 | | - def __enter__(self): |
24 | | - return self |
25 | | - |
26 | | - def __exit__(self, exc_type, exc_val, exc_tb): |
27 | | - self.close() |
28 | | - |
29 | | - def close(self): |
30 | | - pass |
31 | | - |
32 | | - MessageType = typing.Union["PublicMessage", "PublicMessage.SimpleMessageSourceType"] |
33 | | - |
34 | | - def write( |
35 | | - self, |
36 | | - message: Union[MessageType, List[MessageType]], |
37 | | - *args: Optional[MessageType], |
38 | | - timeout: [float, None] = None, |
39 | | - ): |
40 | | - """ |
41 | | - send one or number of messages to server. |
42 | | - it fast put message to internal buffer, without wait message result |
43 | | - return None |
44 | | -
|
45 | | - message will send independent of wait/no wait result |
46 | | -
|
47 | | - timeout - time for waiting for put message into internal queue. |
48 | | - if 0 or negative - non block calls |
49 | | - if None or not set - infinite wait |
50 | | - It will raise TimeoutError() exception if it can't put message to internal queue by limits during timeout. |
51 | | - """ |
52 | | - raise NotImplementedError() |
53 | | - |
54 | | - def async_write_with_ack( |
55 | | - self, |
56 | | - message: Union[MessageType, List[MessageType]], |
57 | | - *args: Optional[MessageType], |
58 | | - timeout: [float, None] = None, |
59 | | - ) -> concurrent.futures.Future: |
60 | | - """ |
61 | | - send one or number of messages to server. |
62 | | - return feature, which can be waited for check send result: ack/duplicate/error |
63 | | -
|
64 | | - Usually it is fast method, but can wait if internal buffer is full. |
65 | | -
|
66 | | - timeout - time for waiting for put message into internal queue. |
67 | | - The method can be blocked up to timeout seconds before return future. |
68 | | -
|
69 | | - if 0 or negative - non block calls |
70 | | - if None or not set - infinite wait |
71 | | - It will raise TimeoutError() exception if it can't put message to internal queue by limits during timeout. |
72 | | - """ |
73 | | - raise NotImplementedError() |
74 | | - |
75 | | - def write_with_ack( |
76 | | - self, |
77 | | - message: Union[MessageType, List[MessageType]], |
78 | | - *args: Optional[MessageType], |
79 | | - buffer_timeout: [float, None] = None, |
80 | | - ) -> Union["MessageWriteStatus", List["MessageWriteStatus"]]: |
81 | | - """ |
82 | | - IT IS SLOWLY WAY. IT IS BAD CHOISE IN MOST CASES. |
83 | | - It is recommended to use write with optionally flush or async_write_with_ack and receive acks by wait future. |
84 | | -
|
85 | | - send one or number of messages to server. |
86 | | - blocked until receive server ack for the message/messages. |
87 | | -
|
88 | | - message will send independent of wait/no wait result |
89 | | -
|
90 | | - buffer_timeout - time for send message to server and receive ack. |
91 | | - if 0 or negative - non block calls |
92 | | - if None or not set - infinite wait |
93 | | - It will raise TimeoutError() exception if it isn't receive ack in timeout |
94 | | - """ |
95 | | - raise NotImplementedError() |
96 | | - |
97 | | - def async_flush(self): |
98 | | - """ |
99 | | - Force send all messages from internal buffer and wait acks from server for all |
100 | | - messages. |
101 | | -
|
102 | | - flush starts of flush process, and return Future for wait result. |
103 | | - messages will be flushed independent of future waiting. |
104 | | - """ |
105 | | - raise NotImplementedError() |
106 | | - |
107 | | - def flush(self, timeout: Optional[float] = None) -> concurrent.futures.Future: |
108 | | - """ |
109 | | - Force send all messages from internal buffer and wait acks from server for all |
110 | | - messages. |
111 | | -
|
112 | | - timeout - time for waiting for send all messages and receive server ack. |
113 | | - if 0 or negative - non block calls |
114 | | - if None or not set - infinite wait |
115 | | - It will raise TimeoutError() exception if it isn't receive ack in timeout |
116 | | - """ |
117 | | - raise NotImplementedError() |
118 | | - |
119 | | - def async_wait_init(self) -> concurrent.futures.Future: |
120 | | - """ |
121 | | - Return feature, which done when underling connection established |
122 | | - """ |
123 | | - raise NotImplementedError() |
124 | | - |
125 | | - def wait_init(self, timeout: Optional[float] = None): |
126 | | - """ |
127 | | - Wait until underling connection established |
128 | | -
|
129 | | - timeout - time for waiting for send all messages and receive server ack. |
130 | | - if 0 or negative - non block calls |
131 | | - if None or not set - infinite wait |
132 | | - It will raise TimeoutError() exception if it isn't receive ack in timeout |
133 | | - """ |
134 | | - raise NotImplementedError() |
| 14 | +MessageType = typing.Union["PublicMessage", "PublicMessage.SimpleMessageSourceType"] |
135 | 15 |
|
136 | 16 |
|
137 | 17 | @dataclass |
|
0 commit comments