Skip to content

Commit 3c33bf5

Browse files
committed
[ADD] infinity loop for websocket
1 parent f1c51fd commit 3c33bf5

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "1.0.7"
1+
VERSION = "1.0.8"

main.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,24 @@ async def catch_exception_internal(req: Request, exc: Exception):
145145

146146
async def producer_webhook(config: Config, timeout: int = 30) -> None:
147147
"""Producer send events to cusomer webhook from config file"""
148-
websocket_client = WebsocketEvents(
149-
ari_config=config.ari_config,
150-
api_key=config.api_key,
151-
api_key_base64=config.api_key_base64,
152-
webhook_url=f"{config.webhook_url}",
153-
timeout=timeout,
154-
)
155-
app.state.websocket_client = websocket_client
156-
157-
await websocket_client.start_consumer()
148+
while True:
149+
try:
150+
websocket_client = WebsocketEvents(
151+
ari_config=config.ari_config,
152+
api_key=config.api_key,
153+
api_key_base64=config.api_key_base64,
154+
webhook_url=f"{config.webhook_url}",
155+
timeout=timeout,
156+
)
157+
app.state.websocket_client = websocket_client
158+
159+
await websocket_client.start_consumer()
160+
except asyncio.CancelledError:
161+
break
162+
except Exception as e:
163+
log.exception("Unknown producer_webhook error: %s", e)
164+
finally:
165+
await asyncio.sleep(timeout)
158166

159167

160168
@app.on_event("startup")

services/websocket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,5 @@ async def start_consumer(self):
224224
self.disconnect_count += 1
225225
self.disconnected_reason = str(exc)
226226
self.disconnected_time = str(datetime.datetime.now())
227-
await asyncio.sleep(self.timeout)
228-
await self.start_consumer()
227+
# await asyncio.sleep(self.timeout)
228+
# await self.start_consumer()

0 commit comments

Comments
 (0)