Skip to content

Commit 276829e

Browse files
committed
Throttle database cleanup to run at most once per hour
1 parent 3fa3df3 commit 276829e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

discord_bot.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def __init__(self, *, intents: discord.Intents) -> None:
234234
super().__init__(intents=intents)
235235
self._last_game_update: float | None = None
236236
self._last_zt_update: float | None = None
237+
self._last_cleanup: float | None = None
237238
self._last_log: float | None = None
238239

239240

@@ -494,7 +495,10 @@ async def main_loop(db: BotDatabase, zt: ZeroTierApiClient | None) -> None:
494495
if zt and zt_api_is_ready:
495496
tasks.append(self.loop.create_task(self._process_zt_members(zt, db)))
496497
self._last_zt_update = now
497-
tasks.append(self.loop.create_task(db.clean_up()))
498+
cleanup_is_ready = not self._last_cleanup or now - self._last_cleanup >= 3600
499+
if cleanup_is_ready:
500+
tasks.append(self.loop.create_task(db.clean_up()))
501+
self._last_cleanup = now
498502
await asyncio.gather(*tasks)
499503
except Exception as e:
500504
logger.exception('Unknown exception occurred: ')

0 commit comments

Comments
 (0)