diff options
| author | 2021-09-11 19:11:12 +0200 | |
|---|---|---|
| committer | 2021-09-11 19:18:13 +0200 | |
| commit | f6a02d8435048d00e1bda31085ea25557f08a228 (patch) | |
| tree | 7ceb7cf242af5263636a722c2a343e152151c224 | |
| parent | Use scheduling create_task util instead of creating from loop directly (diff) | |
Use create_task util instead of asyncio.create_task
The util attaches an error logging callback instead of relying on python's
exception logging which only occurs when the task is destroyed
| -rw-r--r-- | bot/decorators.py | 4 | ||||
| -rw-r--r-- | bot/exts/help_channels/_cog.py | 2 | ||||
| -rw-r--r-- | bot/exts/info/doc/_cog.py | 2 | ||||
| -rw-r--r-- | bot/exts/moderation/defcon.py | 3 | ||||
| -rw-r--r-- | bot/exts/utils/reminders.py | 3 |
5 files changed, 6 insertions, 8 deletions
diff --git a/bot/decorators.py b/bot/decorators.py index f65ec4103..ee210be26 100644 --- a/bot/decorators.py +++ b/bot/decorators.py @@ -10,7 +10,7 @@ from discord.ext import commands from discord.ext.commands import Cog, Context from bot.constants import Channels, DEBUG_MODE, RedirectOutput -from bot.utils import function +from bot.utils import function, scheduling from bot.utils.checks import ContextCheckFailure, in_whitelist_check from bot.utils.function import command_wraps @@ -154,7 +154,7 @@ def redirect_output( if ping_user: await ctx.send(f"Here's the output of your command, {ctx.author.mention}") - asyncio.create_task(func(self, ctx, *args, **kwargs)) + scheduling.create_task(func(self, ctx, *args, **kwargs)) message = await old_channel.send( f"Hey, {ctx.author.mention}, you can find the output of your command here: " diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py index 40fb9429c..8612f9866 100644 --- a/bot/exts/help_channels/_cog.py +++ b/bot/exts/help_channels/_cog.py @@ -507,7 +507,7 @@ class HelpChannels(commands.Cog): """Wait for a dormant channel to become available in the queue and return it.""" log.trace("Waiting for a dormant channel.") - task = asyncio.create_task(self.channel_queue.get()) + task = scheduling.create_task(self.channel_queue.get()) self.queue_tasks.append(task) channel = await task diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py index 6cc1723cd..1624c50f6 100644 --- a/bot/exts/info/doc/_cog.py +++ b/bot/exts/info/doc/_cog.py @@ -458,4 +458,4 @@ class DocCog(commands.Cog): """Clear scheduled inventories, queued symbols and cleanup task on cog unload.""" self.inventory_scheduler.cancel_all() self.init_refresh_task.cancel() - asyncio.create_task(self.item_fetcher.clear(), name="DocCog.item_fetcher unload clear") + scheduling.create_task(self.item_fetcher.clear(), name="DocCog.item_fetcher unload clear") diff --git a/bot/exts/moderation/defcon.py b/bot/exts/moderation/defcon.py index 053e8ae57..ac813d6ba 100644 --- a/bot/exts/moderation/defcon.py +++ b/bot/exts/moderation/defcon.py @@ -1,4 +1,3 @@ -import asyncio import logging import traceback from collections import namedtuple @@ -206,7 +205,7 @@ class Defcon(Cog): new_topic = f"{BASE_CHANNEL_TOPIC}\n(Threshold: {humanize_delta(self.threshold) if self.threshold else '-'})" self.mod_log.ignore(Event.guild_channel_update, Channels.defcon) - asyncio.create_task(self.channel.edit(topic=new_topic)) + scheduling.create_task(self.channel.edit(topic=new_topic)) @defcon_settings.atomic_transaction async def _update_threshold(self, author: User, threshold: relativedelta, expiry: Optional[Expiry] = None) -> None: diff --git a/bot/exts/utils/reminders.py b/bot/exts/utils/reminders.py index 00eb930b5..1030357fd 100644 --- a/bot/exts/utils/reminders.py +++ b/bot/exts/utils/reminders.py @@ -1,4 +1,3 @@ -import asyncio import logging import random import textwrap @@ -81,7 +80,7 @@ class Reminders(Cog): f"Reminder {reminder['id']} invalid: " f"User {reminder['author']}={user}, Channel {reminder['channel_id']}={channel}." ) - asyncio.create_task(self.bot.api_client.delete(f"bot/reminders/{reminder['id']}")) + scheduling.create_task(self.bot.api_client.delete(f"bot/reminders/{reminder['id']}")) return is_valid, user, channel |