Fix some potential exceptions when asyncio.gathering
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user