From acc1654572196cf861a37cd9f17bbe9db2111566 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Mon, 25 Apr 2022 20:15:38 +0400 Subject: 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 --- bot/exts/backend/sync/_cog.py | 12 ++++++++++-- 1 file 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) -- cgit v1.2.3