Skip to content

Commit

Permalink
Run message processing in background tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem4590 committed May 12, 2023
1 parent 2ab9808 commit 6ed2b13
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions meeseeks/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def _init_apps(self) -> list[_T]:

return app_instances

async def loop(self) -> None:
"""Method is intended for calling in endless loop to process Rocket.Chat callbacks. """
async def message_handler(self, message: str) -> None:
"""Serializes message context and run processing for each app. """

raw_context: WebSocketClientProtocol = json.loads(await self._websocket.recv())
raw_context: WebSocketClientProtocol = json.loads(message)
if raw_context.get('msg') == 'ping':
await self._rtapi.pong()
return None
Expand Down Expand Up @@ -193,9 +193,9 @@ async def run(self) -> None:
self.check_app_name(app)
await app.setup()

while True:
async for message in websocket:
try:
await self.loop()
asyncio.create_task(self.message_handler(message))
except ClientResponseError as exc:
LOGGER.error(exc)
except ConnectionClosedOK:
Expand Down

0 comments on commit 6ed2b13

Please sign in to comment.