aboutsummaryrefslogtreecommitdiffstats
path: root/bot/utils/scheduling.py
diff options
context:
space:
mode:
authorGravatar ToxicKidz <[email protected]>2021-04-12 11:54:13 -0400
committerGravatar GitHub <[email protected]>2021-04-12 23:54:13 +0800
commitfcfa287e96bf0eedcb2fe0bc2e004794324beeb2 (patch)
tree27bae984edeb9e5dd8dd288d1a40adb12acc1e29 /bot/utils/scheduling.py
parentMerge pull request #1014 from Numerlor/doc-imp (diff)
Remove reactions from everyone when paginating and waiting for trashcan reaction. (#1471)
* Remove reactions from everyone * Make flake8 happy * Make flake8 happy again * Remove reactions in check functions * Make flake8 happy for the last time * Update bot/pagination.py Co-authored-by: Kieran Siek <[email protected]> * Make create_task one line and return False in checks * Fix return so it returns either True or False * Use scheduling.create_task and suppress HTTPException * Suppress HTTPException in scheduling.create_task * Remove double if-statements Co-authored-by: Mark <[email protected]> * change suppress_exceptions to suppressed_exceptions * Make suppressed_exceptions a kwargs for _log_task_exception * Update scheduling.create_task call to correspond with *args * Fix NameError: reaction, user -> reaction_, user_ * Update scheduling.create_task call to correspond with *args in messages.wait_for_deletion * reaction -> reaction_ * Ignore reactions from the bot * Fix type annotations for create_task * Refactor add_reaction check to a separate function * Name the remove_reaction task Co-authored-by: Kieran Siek <[email protected]> Co-authored-by: Mark <[email protected]>
Diffstat (limited to '')
-rw-r--r--bot/utils/scheduling.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/bot/utils/scheduling.py b/bot/utils/scheduling.py
index 6843bae88..2dc485f24 100644
--- a/bot/utils/scheduling.py
+++ b/bot/utils/scheduling.py
@@ -161,18 +161,18 @@ class Scheduler:
self._log.error(f"Error in task #{task_id} {id(done_task)}!", exc_info=exception)
-def create_task(*args, **kwargs) -> asyncio.Task:
+def create_task(coro: t.Awaitable, *suppressed_exceptions: t.Type[Exception], **kwargs) -> asyncio.Task:
"""Wrapper for `asyncio.create_task` which logs exceptions raised in the task."""
- task = asyncio.create_task(*args, **kwargs)
- task.add_done_callback(_log_task_exception)
+ task = asyncio.create_task(coro, **kwargs)
+ task.add_done_callback(partial(_log_task_exception, suppressed_exceptions=suppressed_exceptions))
return task
-def _log_task_exception(task: asyncio.Task) -> None:
+def _log_task_exception(task: asyncio.Task, *, suppressed_exceptions: t.Tuple[t.Type[Exception]]) -> None:
"""Retrieve and log the exception raised in `task` if one exists."""
with contextlib.suppress(asyncio.CancelledError):
exception = task.exception()
# Log the exception if one exists.
- if exception:
+ if exception and not isinstance(exception, suppressed_exceptions):
log = logging.getLogger(__name__)
log.error(f"Error in task {task.get_name()} {id(task)}!", exc_info=exception)