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
+27 -18
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, for attempt in range(max_retries):
initial_state=[ try:
{ dm_room = await self.client.create_room(
"type": str(EventType.ROOM_NAME), preset=RoomCreatePreset.PRIVATE,
"content": {"name": f"[{roomname}] join verification"} invitees=[evt.sender],
} is_direct=True,
] initial_state=[
) {
self.log.info(f"Created DM room {dm_room} for {evt.sender}") "type": str(EventType.ROOM_NAME),
"content": {"name": f"[{roomname}] join verification"}
}
except Exception as e: ]
self.log.error(f"Failed to initiate verification process: {e}") )
return 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"])