Skip to content

Commit

Permalink
Hack to make matrix connector more reliable
Browse files Browse the repository at this point in the history
It is a hack for issue opsdroid#26
  • Loading branch information
szimszon committed Jun 4, 2018
1 parent e989b84 commit 84e90cb
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,18 @@ async def listen(self, opsdroid):
# Listen for new messages from the chat service
while True:
try:
response = await self.connection.sync(
self.connection.sync_token,
timeout_ms=int(6 * 60 * 60 * 1e3), # 6h in ms
filter=self.filter_id)
try:
response = await self.connection.sync(
self.connection.sync_token,
timeout_ms=int(6 * 60 * 60 * 1e3), # 6h in ms
filter=self.filter_id)
except aiohttp.client_exceptions.ServerDisconnectedError:
# Retry after the faild first attempt (issue #26)
_LOGGER.debug("retry sync after the failed first attempt")
response = await self.connection.sync(
self.connection.sync_token,
timeout_ms=int(6 * 60 * 60 * 1e3), # 6h in ms
filter=self.filter_id)
_LOGGER.debug("matrix sync request returned")
self.connection.sync_token = response["next_batch"]
for roomid in self.room_ids.values():
Expand Down Expand Up @@ -160,7 +168,12 @@ async def respond(self, message, roomname=None):
else:
room_id = room_id

await self.connection.send_message(room_id, message.text)
try:
await self.connection.send_message(room_id, message.text)
except aiohttp.client_exceptions.ServerDisconnectedError:
# Retry after the faild first attempt (issue #26)
_LOGGER.debug("retry send after the failed first attempt")
await self.connection.send_message(room_id, message.text)

async def disconnect(self):
self.session.close()

0 comments on commit 84e90cb

Please sign in to comment.