jararaca 0.3.12a11__py3-none-any.whl → 0.3.12a12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jararaca might be problematic. Click here for more details.
- jararaca/presentation/websocket/redis.py +85 -7
- {jararaca-0.3.12a11.dist-info → jararaca-0.3.12a12.dist-info}/METADATA +1 -1
- {jararaca-0.3.12a11.dist-info → jararaca-0.3.12a12.dist-info}/RECORD +7 -7
- pyproject.toml +1 -1
- {jararaca-0.3.12a11.dist-info → jararaca-0.3.12a12.dist-info}/LICENSE +0 -0
- {jararaca-0.3.12a11.dist-info → jararaca-0.3.12a12.dist-info}/WHEEL +0 -0
- {jararaca-0.3.12a11.dist-info → jararaca-0.3.12a12.dist-info}/entry_points.txt +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
+
import logging
|
|
2
3
|
from dataclasses import dataclass
|
|
3
4
|
from typing import Any
|
|
4
5
|
|
|
@@ -10,6 +11,8 @@ from jararaca.presentation.websocket.websocket_interceptor import (
|
|
|
10
11
|
WebSocketConnectionBackend,
|
|
11
12
|
)
|
|
12
13
|
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
13
16
|
|
|
14
17
|
@dataclass
|
|
15
18
|
class BroadcastMessage:
|
|
@@ -66,6 +69,34 @@ class RedisWebSocketConnectionBackend(WebSocketConnectionBackend):
|
|
|
66
69
|
|
|
67
70
|
self.consume_broadcast_timeout = consume_broadcast_timeout
|
|
68
71
|
self.consume_send_timeout = consume_send_timeout
|
|
72
|
+
self.__shutdown_event: asyncio.Event | None = None
|
|
73
|
+
|
|
74
|
+
self.__send_func: SendFunc | None = None
|
|
75
|
+
self.__broadcast_func: BroadcastFunc | None = None
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def shutdown_event(self) -> asyncio.Event:
|
|
79
|
+
if self.__shutdown_event is None:
|
|
80
|
+
raise RuntimeError(
|
|
81
|
+
"Shutdown event is not set. Please configure the backend before using it."
|
|
82
|
+
)
|
|
83
|
+
return self.__shutdown_event
|
|
84
|
+
|
|
85
|
+
@property
|
|
86
|
+
def send_func(self) -> SendFunc:
|
|
87
|
+
if self.__send_func is None:
|
|
88
|
+
raise RuntimeError(
|
|
89
|
+
"Send function is not set. Please configure the backend before using it."
|
|
90
|
+
)
|
|
91
|
+
return self.__send_func
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def broadcast_func(self) -> BroadcastFunc:
|
|
95
|
+
if self.__broadcast_func is None:
|
|
96
|
+
raise RuntimeError(
|
|
97
|
+
"Broadcast function is not set. Please configure the backend before using it."
|
|
98
|
+
)
|
|
99
|
+
return self.__broadcast_func
|
|
69
100
|
|
|
70
101
|
async def broadcast(self, message: bytes) -> None:
|
|
71
102
|
await self.redis.publish(
|
|
@@ -82,22 +113,69 @@ class RedisWebSocketConnectionBackend(WebSocketConnectionBackend):
|
|
|
82
113
|
def configure(
|
|
83
114
|
self, broadcast: BroadcastFunc, send: SendFunc, shutdown_event: asyncio.Event
|
|
84
115
|
) -> None:
|
|
116
|
+
if self.__shutdown_event is not None:
|
|
117
|
+
raise RuntimeError("Backend is already configured.")
|
|
118
|
+
self.__shutdown_event = shutdown_event
|
|
119
|
+
self.__send_func = send
|
|
120
|
+
self.__broadcast_func = broadcast
|
|
121
|
+
self.setup_send_consumer()
|
|
122
|
+
self.setup_broadcast_consumer()
|
|
85
123
|
|
|
86
|
-
|
|
87
|
-
self.consume_broadcast(broadcast, shutdown_event)
|
|
88
|
-
)
|
|
124
|
+
def setup_send_consumer(self) -> None:
|
|
89
125
|
|
|
90
126
|
send_task = asyncio.get_event_loop().create_task(
|
|
91
|
-
self.consume_send(
|
|
127
|
+
self.consume_send(self.send_func, self.shutdown_event)
|
|
92
128
|
)
|
|
93
129
|
|
|
94
|
-
self.tasks.add(broadcast_task)
|
|
95
130
|
self.tasks.add(send_task)
|
|
131
|
+
send_task.add_done_callback(self.handle_send_task_done)
|
|
132
|
+
|
|
133
|
+
def setup_broadcast_consumer(self) -> None:
|
|
134
|
+
|
|
135
|
+
broadcast_task = asyncio.get_event_loop().create_task(
|
|
136
|
+
self.consume_broadcast(self.broadcast_func, self.shutdown_event)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
self.tasks.add(broadcast_task)
|
|
140
|
+
|
|
141
|
+
broadcast_task.add_done_callback(self.handle_broadcast_task_done)
|
|
142
|
+
|
|
143
|
+
def handle_broadcast_task_done(self, task: asyncio.Task[Any]) -> None:
|
|
144
|
+
if task.cancelled():
|
|
145
|
+
logger.warning("Broadcast task was cancelled.")
|
|
146
|
+
elif task.exception() is not None:
|
|
147
|
+
logger.exception(
|
|
148
|
+
f"Broadcast task raised an exception:", exc_info=task.exception()
|
|
149
|
+
)
|
|
150
|
+
else:
|
|
151
|
+
logger.warning("Broadcast task somehow completed successfully.")
|
|
152
|
+
|
|
153
|
+
if not self.shutdown_event.is_set():
|
|
154
|
+
logger.warning(
|
|
155
|
+
"Broadcast task completed, but shutdown event is not set. This is unexpected."
|
|
156
|
+
)
|
|
157
|
+
self.setup_broadcast_consumer()
|
|
158
|
+
|
|
159
|
+
def handle_send_task_done(self, task: asyncio.Task[Any]) -> None:
|
|
160
|
+
if task.cancelled():
|
|
161
|
+
logger.warning("Send task was cancelled.")
|
|
162
|
+
elif task.exception() is not None:
|
|
163
|
+
logger.exception(
|
|
164
|
+
f"Send task raised an exception:", exc_info=task.exception()
|
|
165
|
+
)
|
|
166
|
+
else:
|
|
167
|
+
logger.warning("Send task somehow completed successfully.")
|
|
168
|
+
|
|
169
|
+
if not self.shutdown_event.is_set():
|
|
170
|
+
logger.warning(
|
|
171
|
+
"Send task completed, but shutdown event is not set. This is unexpected."
|
|
172
|
+
)
|
|
173
|
+
self.setup_send_consumer()
|
|
96
174
|
|
|
97
175
|
async def consume_broadcast(
|
|
98
176
|
self, broadcast: BroadcastFunc, shutdown_event: asyncio.Event
|
|
99
177
|
) -> None:
|
|
100
|
-
|
|
178
|
+
logger.info("Starting broadcast consumer...")
|
|
101
179
|
async with self.redis.pubsub() as pubsub:
|
|
102
180
|
await pubsub.subscribe(self.broadcast_pubsub_channel)
|
|
103
181
|
|
|
@@ -122,7 +200,7 @@ class RedisWebSocketConnectionBackend(WebSocketConnectionBackend):
|
|
|
122
200
|
task.add_done_callback(self.tasks.discard)
|
|
123
201
|
|
|
124
202
|
async def consume_send(self, send: SendFunc, shutdown_event: asyncio.Event) -> None:
|
|
125
|
-
|
|
203
|
+
logger.info("Starting send consumer...")
|
|
126
204
|
async with self.redis.pubsub() as pubsub:
|
|
127
205
|
await pubsub.subscribe(self.send_pubsub_channel)
|
|
128
206
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
2
2
|
README.md,sha256=2qMM__t_MoLKZr4IY9tXjo-Jn6LKjuHMb1qbyXpgL08,3401
|
|
3
|
-
pyproject.toml,sha256=
|
|
3
|
+
pyproject.toml,sha256=AUHfpadnBMMpRGIwDj74rGk7IoPl3zyOxhAAcDyIYz4,2041
|
|
4
4
|
jararaca/__init__.py,sha256=h3MkFZ9xNllb-YTB-M1WH2HnSJbkev6t1c984Nn6G1w,21887
|
|
5
5
|
jararaca/__main__.py,sha256=-O3vsB5lHdqNFjUtoELDF81IYFtR-DSiiFMzRaiSsv4,67
|
|
6
6
|
jararaca/broker_backend/__init__.py,sha256=GzEIuHR1xzgCJD4FE3harNjoaYzxHMHoEL0_clUaC-k,3528
|
|
@@ -47,7 +47,7 @@ jararaca/presentation/websocket/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
|
|
|
47
47
|
jararaca/presentation/websocket/base_types.py,sha256=AvUeeZ1TFhSiRMcYqZU1HaQNqSrcgTkC5R0ArP5dGmA,146
|
|
48
48
|
jararaca/presentation/websocket/context.py,sha256=A6K5W3kqo9Hgeh1m6JiI7Cdz5SfbXcaICSVX7u1ARZo,1903
|
|
49
49
|
jararaca/presentation/websocket/decorators.py,sha256=ZNd5aoA9UkyfHOt1C8D2Ffy2gQUNDEsusVnQuTgExgs,2157
|
|
50
|
-
jararaca/presentation/websocket/redis.py,sha256
|
|
50
|
+
jararaca/presentation/websocket/redis.py,sha256=-TiLQ2ZEBDaB-HVvbuehEZ5KMfvnZ09kLJW-I1m15ss,7709
|
|
51
51
|
jararaca/presentation/websocket/types.py,sha256=M8snAMSdaQlKrwEM2qOgF2qrefo5Meio_oOw620Joc8,308
|
|
52
52
|
jararaca/presentation/websocket/websocket_interceptor.py,sha256=JWn_G8Q2WO0-1kmN7-Gv0HkIM6nZ_yjCdGRuXUS8F7A,9191
|
|
53
53
|
jararaca/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -74,8 +74,8 @@ jararaca/tools/typescript/interface_parser.py,sha256=SsTgYUWhX79e2rvcu5A5kvs7bJ3
|
|
|
74
74
|
jararaca/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
75
75
|
jararaca/utils/rabbitmq_utils.py,sha256=ytdAFUyv-OBkaVnxezuJaJoLrmN7giZgtKeet_IsMBs,10918
|
|
76
76
|
jararaca/utils/retry.py,sha256=DzPX_fXUvTqej6BQ8Mt2dvLo9nNlTBm7Kx2pFZ26P2Q,4668
|
|
77
|
-
jararaca-0.3.
|
|
78
|
-
jararaca-0.3.
|
|
79
|
-
jararaca-0.3.
|
|
80
|
-
jararaca-0.3.
|
|
81
|
-
jararaca-0.3.
|
|
77
|
+
jararaca-0.3.12a12.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
78
|
+
jararaca-0.3.12a12.dist-info/METADATA,sha256=kQe6CbKZg0aA8kh3cfX8E0nOsSpx__Dm7MvtTulq5jA,4996
|
|
79
|
+
jararaca-0.3.12a12.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
80
|
+
jararaca-0.3.12a12.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
|
|
81
|
+
jararaca-0.3.12a12.dist-info/RECORD,,
|
pyproject.toml
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|