aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2020-12-11 23:44:59 +0100
committerGravatar Numerlor <[email protected]>2020-12-15 05:02:11 +0100
commit121bdd16e8ee53d83822e9320232a65ea2ab540a (patch)
tree3cec42d9c038ffd17b3a5c51b46ea80700ab5c87
parentEnsure only one future is created for each doc_item (diff)
Move parse_queue cleanup into finally block
The finally will make sure we reset the task and log it no matter what happens, additionally the clearing of the variable is now only done in one place as the finally also executes when the coro is cancelled
-rw-r--r--bot/exts/info/doc/_cog.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py
index 78d9c6b9b..603d7df97 100644
--- a/bot/exts/info/doc/_cog.py
+++ b/bot/exts/info/doc/_cog.py
@@ -117,20 +117,21 @@ class CachedParser:
The coroutine will run as long as the queue is not empty, resetting `self._parse_task` to None when finished.
"""
log.trace("Starting queue parsing.")
- while self._queue:
- item, soup = self._queue.pop()
- try:
- markdown = get_symbol_markdown(soup, item)
- await doc_cache.set(item, markdown)
- except Exception:
- log.exception(f"Unexpected error when handling {item}")
- else:
- if (future := self._item_futures.get(item)) is not None:
- future.set_result(markdown)
- await asyncio.sleep(0.1)
-
- self._parse_task = None
- log.trace("Finished parsing queue.")
+ try:
+ while self._queue:
+ item, soup = self._queue.pop()
+ try:
+ markdown = get_symbol_markdown(soup, item)
+ await doc_cache.set(item, markdown)
+ except Exception:
+ log.exception(f"Unexpected error when handling {item}")
+ else:
+ if (future := self._item_futures.get(item)) is not None:
+ future.set_result(markdown)
+ await asyncio.sleep(0.1)
+ finally:
+ self._parse_task = None
+ log.trace("Finished parsing queue.")
def _move_to_front(self, item: Union[QueueItem, DocItem]) -> None:
"""Map a DocItem to its page so that the symbol will be parsed once the page is requested."""
@@ -155,7 +156,6 @@ class CachedParser:
await future
if self._parse_task is not None:
self._parse_task.cancel()
- self._parse_task = None
self._queue.clear()
self._page_symbols.clear()
self._item_futures.clear()