Fix some potential exceptions when asyncio.gathering

This commit is contained in:
Tulir Asokan
2019-09-02 22:21:48 +03:00
parent fbb1267609
commit 3c2268870b
4 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -318,7 +318,7 @@ class AbstractUser(ABC):
try:
users = (entity for entity in entities.values() if isinstance(entity, User))
puppets = ((pu.Puppet.get(TelegramID(user.id)), user) for user in users)
await asyncio.gather(*[puppet.update_info(self, info)
await asyncio.gather(*[puppet.try_update_info(self, info)
for puppet, info in puppets if puppet])
except Exception:
self.log.exception("Failed to handle entity updates")
+1 -1
View File
@@ -61,7 +61,7 @@ async def clear_db_cache(evt: CommandEvent) -> EventID:
for puppet in pu.Puppet.by_custom_mxid.values():
puppet.sync_task.cancel()
pu.Puppet.by_custom_mxid = {}
await asyncio.gather(*[puppet.start() for puppet in pu.Puppet.all_with_custom_mxid()],
await asyncio.gather(*[puppet.try_start() for puppet in pu.Puppet.all_with_custom_mxid()],
loop=evt.loop)
await evt.reply("Cleared puppet cache and restarted custom puppet syncers")
elif section == "user":
+5 -1
View File
@@ -226,7 +226,11 @@ class PortalMetadata(BasePortal, ABC):
if self.mxid:
if update_if_exists:
if not entity:
entity = await self.get_entity(user)
try:
entity = await self.get_entity(user)
except Exception:
self.log.exception(f"Failed to get entity through {user.tgid} for update")
return self.mxid
update = self.update_matrix_room(user, entity, self.peer_type == "user")
if synchronous:
await update
+6
View File
@@ -226,6 +226,12 @@ class Puppet(CustomPuppetMixin):
return name
return cls.displayname_template.format_full(name)
async def try_update_info(self, source: 'AbstractUser', info: User) -> None:
try:
await self.update_info(source, info)
except Exception:
source.log.exception(f"Failed to update info of {self.tgid}")
async def update_info(self, source: 'AbstractUser', info: User) -> None:
if self.disable_updates:
return