Skip to content

Commit 40ea9a3

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

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

main.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +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+
148149
while True:
149150
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
151+
if not app.state.websocket_client:
152+
websocket_client = WebsocketEvents(
153+
ari_config=config.ari_config,
154+
api_key=config.api_key,
155+
api_key_base64=config.api_key_base64,
156+
webhook_url=f"{config.webhook_url}",
157+
timeout=timeout,
158+
)
159+
app.state.websocket_client = websocket_client
158160

159161
await websocket_client.start_consumer()
160162
except asyncio.CancelledError:
161163
break
162-
except Exception as e:
163-
log.exception("Unknown producer_webhook error: %s", e)
164+
except Exception as exc:
165+
log.exception("Unknown producer_webhook error: %s", exc)
164166
finally:
165167
await asyncio.sleep(timeout)
166168

services/websocket.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(
4747
self.api_key_base64 = api_key_base64
4848

4949
self.websocket_url = (
50-
f"{websocket_url}?api_key={api_key}&app=AsteriskAgentPythonDev&subscribeAll=true"
50+
f"{websocket_url}?api_key={api_key}&app=AsteriskAgentPython&subscribeAll=true"
5151
)
5252
self.webhook_url = webhook_url
5353
self.timeout = timeout
@@ -224,5 +224,6 @@ 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+
raise exc
227228
# await asyncio.sleep(self.timeout)
228229
# await self.start_consumer()

0 commit comments

Comments
 (0)