diff options
author | 2022-04-25 20:15:38 +0400 | |
---|---|---|
committer | 2022-04-25 21:33:33 +0400 | |
commit | acc1654572196cf861a37cd9f17bbe9db2111566 (patch) | |
tree | 7d29ea0df495b73625cd8778c79d2d88852d531a | |
parent | Speed Up Sync Cog Loading (diff) |
Add Timeout To The Sync Cog
Adds a 30-minute timeout while waiting for the guild to be chunked in
the sync cog, after which the cog is not loaded.
Signed-off-by: Hassan Abouelela <[email protected]>
-rw-r--r-- | bot/exts/backend/sync/_cog.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/bot/exts/backend/sync/_cog.py b/bot/exts/backend/sync/_cog.py index 4ec822d3f..85266340b 100644 --- a/bot/exts/backend/sync/_cog.py +++ b/bot/exts/backend/sync/_cog.py @@ -1,10 +1,11 @@ import asyncio +import datetime from typing import Any, Dict from botcore.site_api import ResponseCodeError from discord import Member, Role, User from discord.ext import commands -from discord.ext.commands import Cog, Context +from discord.ext.commands import Cog, Context, errors from bot import constants from bot.bot import Bot @@ -29,10 +30,17 @@ class Sync(Cog): return log.info("Waiting for guild to be chunked to start syncers.") + end = datetime.datetime.now() + datetime.timedelta(minutes=30) while not guild.chunked: await asyncio.sleep(10) - log.info("Starting syncers.") + if datetime.datetime.now() > end: + # More than 30 minutes have passed while trying, abort + raise errors.ExtensionFailed( + self.__class__.__name__, + RuntimeError("The guild was not chunked in time, not loading sync cog.") + ) + log.info("Starting syncers.") for syncer in (_syncers.RoleSyncer, _syncers.UserSyncer): await syncer.sync(guild) |