aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2021-09-05 09:34:54 +0100
committerGravatar Chris Lovering <[email protected]>2021-09-06 12:56:33 +0100
commit6bb0dba2230e9b3fcab2caaf559b749543c26abb (patch)
treec908bbe700fb68d2b566983dbb799121de6d7b65
parentServer command now uses correct TalentPool attr (#1810) (diff)
Declare and refresh TalentPool.cache on init of cog
This avoids issues in the server cog trying to access it before it's assigned and refreshed. I also migrated to the tasks to `scheduling.create_task()` as the created tasks currently don't have any error handling they can hide errors in development until the task object is destroyed (if that occurs at all) which logs the exception. The scheduling alternative attaches a callback which logs exceptions to prevent this.
-rw-r--r--bot/exts/info/information.py3
-rw-r--r--bot/exts/recruitment/talentpool/_cog.py9
-rw-r--r--bot/exts/recruitment/talentpool/_review.py2
3 files changed, 8 insertions, 6 deletions
diff --git a/bot/exts/info/information.py b/bot/exts/info/information.py
index 51d47b75c..d44886969 100644
--- a/bot/exts/info/information.py
+++ b/bot/exts/info/information.py
@@ -72,7 +72,8 @@ class Information(Cog):
"""Return additional server info only visible in moderation channels."""
talentpool_info = ""
if cog := self.bot.get_cog("Talentpool"):
- talentpool_info = f"Nominated: {len(cog.cache)}\n"
+ num_nominated = len(cog.cache) if cog.cache else 0
+ talentpool_info = f"Nominated: {num_nominated}\n"
bb_info = ""
if cog := self.bot.get_cog("Big Brother"):
diff --git a/bot/exts/recruitment/talentpool/_cog.py b/bot/exts/recruitment/talentpool/_cog.py
index a317c6645..bea5ff72c 100644
--- a/bot/exts/recruitment/talentpool/_cog.py
+++ b/bot/exts/recruitment/talentpool/_cog.py
@@ -2,7 +2,7 @@ import logging
import textwrap
from collections import ChainMap, defaultdict
from io import StringIO
-from typing import Union
+from typing import Optional, Union
import discord
from async_rediscache import RedisCache
@@ -15,7 +15,7 @@ from bot.constants import Channels, Emojis, Guild, MODERATION_ROLES, Roles, STAF
from bot.converters import MemberOrUser
from bot.exts.recruitment.talentpool._review import Reviewer
from bot.pagination import LinePaginator
-from bot.utils import time
+from bot.utils import scheduling, time
from bot.utils.time import get_time_delta
AUTOREVIEW_ENABLED_KEY = "autoreview_enabled"
@@ -34,8 +34,11 @@ class TalentPool(Cog, name="Talentpool"):
def __init__(self, bot: Bot) -> None:
self.bot = bot
self.reviewer = Reviewer(self.__class__.__name__, bot, self)
+ self.cache: Optional[defaultdict[dict]] = None
self.api_default_params = {'active': 'true', 'ordering': '-inserted_at'}
- self.bot.loop.create_task(self.schedule_autoreviews())
+
+ scheduling.create_task(self.refresh_cache(), event_loop=self.bot.loop)
+ scheduling.create_task(self.schedule_autoreviews(), event_loop=self.bot.loop)
async def schedule_autoreviews(self) -> None:
"""Reschedule reviews for active nominations if autoreview is enabled."""
diff --git a/bot/exts/recruitment/talentpool/_review.py b/bot/exts/recruitment/talentpool/_review.py
index 3ffbf93f3..f4aa73e75 100644
--- a/bot/exts/recruitment/talentpool/_review.py
+++ b/bot/exts/recruitment/talentpool/_review.py
@@ -57,8 +57,6 @@ class Reviewer:
"""Reschedule all active nominations to be reviewed at the appropriate time."""
log.trace("Rescheduling reviews")
await self.bot.wait_until_guild_available()
- # TODO Once the watch channel is removed, this can be done in a smarter way, e.g create a sync function.
- await self._pool.refresh_cache()
for user_id, user_data in self._pool.cache.items():
if not user_data["reviewed"]: