From a430f1aefdb092bc7ca2fd41bff20aedaa949f5e Mon Sep 17 00:00:00 2001 From: Numerlor <25886452+Numerlor@users.noreply.github.com> Date: Tue, 15 Dec 2020 00:35:12 +0100 Subject: Wait for the inventory to be refreshed before attempting any fetching Previously the bot returned an error if a symbol was not found while inventories were refreshing, but we can just wait for the to finish refreshing and then the symbol may be filled in. A logging call to notify of the refresh being done was also added. --- bot/exts/info/doc/_cog.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py index 0d344c363..a8642be3e 100644 --- a/bot/exts/info/doc/_cog.py +++ b/bot/exts/info/doc/_cog.py @@ -304,6 +304,7 @@ class DocCog(commands.Cog): ) for package in await self.bot.api_client.get('bot/documentation-links') ] await asyncio.gather(*coros) + log.debug("Finished inventory refresh.") REFRESH_EVENT.set() async def get_symbol_embed(self, symbol: str) -> Optional[discord.Embed]: @@ -316,6 +317,10 @@ class DocCog(commands.Cog): if not present also create a redis entry for the symbol. """ log.trace(f"Building embed for symbol `{symbol}`") + if not REFRESH_EVENT.is_set(): + log.debug("Waiting for inventories to be refreshed before processing item.") + await REFRESH_EVENT.wait() + symbol_info = self.doc_symbols.get(symbol) if symbol_info is None: log.debug("Symbol does not exist.") @@ -325,9 +330,6 @@ class DocCog(commands.Cog): markdown = await doc_cache.get(symbol_info) if markdown is None: log.debug(f"Redis cache miss for symbol `{symbol}`.") - if not REFRESH_EVENT.is_set(): - log.debug("Waiting for inventories to be refreshed before processing item.") - await REFRESH_EVENT.wait() markdown = await self.item_fetcher.get_markdown(symbol_info) if markdown is not None: await doc_cache.set(symbol_info, markdown) -- cgit v1.2.3