Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions bot/exts/backend/sync/_cog.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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, errors
from discord.ext.commands import Cog, Context

from bot import constants
from bot.bot import Bot
from bot.exts.backend.sync import _syncers
from bot.log import get_logger

log = get_logger(__name__)
MAX_ATTEMPTS = 3


class Sync(Cog):
Expand All @@ -29,16 +29,20 @@ async def cog_load(self) -> None:
if guild is None:
return

log.info("Waiting for guild to be chunked to start syncers.")
end = datetime.datetime.now() + datetime.timedelta(minutes=30)
while not guild.chunked:
attempts = 0
while True:
attempts += 1
if guild.chunked:
log.info("Guild was found to be chunked after %d attempt(s).", attempts)
break

if attempts == MAX_ATTEMPTS:
log.info("Guild not chunked after %d attempts, calling chunk manually.", MAX_ATTEMPTS)
await guild.chunk()
Comment thread
HassanAbouelela marked this conversation as resolved.
break

log.info("Attempt %d/%d: Guild not yet chunked, checking again in 10s.", attempts, MAX_ATTEMPTS)
await asyncio.sleep(10)
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):
Expand Down