Add timeout for backfill queue waiter to handle retries

This commit is contained in:
Tulir Asokan
2022-10-11 17:32:59 +03:00
parent 699fc9df1f
commit 8ae34223c5
2 changed files with 6 additions and 3 deletions
+1 -1
View File
@@ -167,7 +167,7 @@ class Backfill:
q = "UPDATE backfill_queue SET completed_at=$1 WHERE queue_id=$2"
await self.db.execute(q, datetime.now(), self.queue_id)
async def set_cooldown_timeout(self, timeout) -> None:
async def set_cooldown_timeout(self, timeout: int) -> None:
"""
Set the backfill request to cooldown for ``timeout`` seconds.
"""
+5 -2
View File
@@ -382,7 +382,10 @@ class User(DBUser, AbstractUser, BaseUser):
while True:
req = await Backfill.get_next(self.mxid)
if not req:
await self.wakeup_backfill_task.wait()
try:
await asyncio.wait_for(self.wakeup_backfill_task.wait(), timeout=300)
except asyncio.TimeoutError:
pass
self.wakeup_backfill_task.clear()
else:
await self._takeout_and_backfill(req)
@@ -439,7 +442,7 @@ class User(DBUser, AbstractUser, BaseUser):
await asyncio.sleep(req.post_batch_delay)
except Exception:
self.log.exception("Error handling backfill request for %s", req.portal_tgid)
await req.set_cooldown_timeout(10)
await req.set_cooldown_timeout(1800)
async def update(self, update: TypeUpdate) -> bool:
if not self.is_bot: