add some retry logic to the verification initialization

This commit is contained in:
William Kray
2025-04-19 10:43:09 -07:00
parent 481f3fbaaf
commit 28198e87c5
+26 -17
View File
@@ -905,24 +905,33 @@ class CommunityBot(Plugin):
return return
# Create DM room with name # Create DM room with name
try: max_retries = 3
dm_room = await self.client.create_room( retry_delay = 1 # seconds
preset=RoomCreatePreset.PRIVATE, last_error = None
invitees=[evt.sender],
is_direct=True,
initial_state=[
{
"type": str(EventType.ROOM_NAME),
"content": {"name": f"[{roomname}] join verification"}
}
]
)
self.log.info(f"Created DM room {dm_room} for {evt.sender}")
for attempt in range(max_retries):
except Exception as e: try:
self.log.error(f"Failed to initiate verification process: {e}") dm_room = await self.client.create_room(
return preset=RoomCreatePreset.PRIVATE,
invitees=[evt.sender],
is_direct=True,
initial_state=[
{
"type": str(EventType.ROOM_NAME),
"content": {"name": f"[{roomname}] join verification"}
}
]
)
self.log.info(f"Created DM room {dm_room} for {evt.sender}")
break
except Exception as e:
last_error = e
if attempt < max_retries - 1: # Don't sleep on the last attempt
self.log.warning(f"Failed to create DM room (attempt {attempt + 1}/{max_retries}): {e}")
await asyncio.sleep(retry_delay)
else:
self.log.error(f"Failed to initiate verification process after {max_retries} attempts: {e}")
return
# Select random verification phrase # Select random verification phrase
verification_phrase = random.choice(self.config["verification_phrases"]) verification_phrase = random.choice(self.config["verification_phrases"])