mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-08 18:32:32 -05:00
Audio cleanup (#5618)
* add different logging level callbacks for task exception logging * Add callback to tasks which didn't have them * The boring stuff - (apply .trace() and .verbose() to audio, stop using debug_exc_log, delete audio_logging.py) * Unsured import cleanup * use new lavalink method * return so it doesn't log this twice. * improve logging on main event handler
This commit is contained in:
@@ -10,6 +10,7 @@ from ...errors import LavalinkDownloadFailed
|
||||
from ...manager import ServerManager
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import CompositeMetaClass
|
||||
from ...utils import task_callback_debug
|
||||
|
||||
log = logging.getLogger("red.cogs.Audio.cog.Tasks.lavalink")
|
||||
_ = Translator("Audio", Path(__file__))
|
||||
@@ -28,6 +29,7 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
lavalink.register_event_listener(self.lavalink_event_handler)
|
||||
lavalink.register_update_listener(self.lavalink_update_handler)
|
||||
self.lavalink_connect_task = self.bot.loop.create_task(self.lavalink_attempt_connect())
|
||||
self.lavalink_connect_task.add_done_callback(task_callback_debug)
|
||||
|
||||
async def lavalink_attempt_connect(self, timeout: int = 50) -> None:
|
||||
self.lavalink_connection_aborted = False
|
||||
@@ -63,10 +65,10 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
exc_info=exc,
|
||||
)
|
||||
self.lavalink_connection_aborted = True
|
||||
raise
|
||||
return
|
||||
except asyncio.CancelledError:
|
||||
log.exception("Invalid machine architecture, cannot run Lavalink.")
|
||||
raise
|
||||
log.critical("Invalid machine architecture, cannot run Lavalink.")
|
||||
return
|
||||
except Exception as exc:
|
||||
log.exception(
|
||||
"Unhandled exception whilst starting internal Lavalink server, "
|
||||
@@ -74,7 +76,7 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
exc_info=exc,
|
||||
)
|
||||
self.lavalink_connection_aborted = True
|
||||
raise
|
||||
return
|
||||
else:
|
||||
break
|
||||
else:
|
||||
@@ -104,7 +106,7 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
resume_key=f"Red-Core-Audio-{self.bot.user.id}-{data_manager.instance_name}",
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
log.error("Connecting to Lavalink server timed out, retrying...")
|
||||
log.warning("Connecting to Lavalink server timed out, retrying...")
|
||||
if external is False and self.player_manager is not None:
|
||||
await self.player_manager.shutdown()
|
||||
retry_count += 1
|
||||
@@ -114,7 +116,7 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
"Unhandled exception whilst connecting to Lavalink, aborting...", exc_info=exc
|
||||
)
|
||||
self.lavalink_connection_aborted = True
|
||||
raise
|
||||
return
|
||||
else:
|
||||
break
|
||||
else:
|
||||
@@ -127,3 +129,4 @@ class LavalinkTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if external:
|
||||
await asyncio.sleep(5)
|
||||
self._restore_task = asyncio.create_task(self.restore_players())
|
||||
self._restore_task.add_done_callback(task_callback_debug)
|
||||
|
||||
@@ -10,7 +10,6 @@ import lavalink
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import AsyncIter
|
||||
|
||||
from ...audio_logging import debug_exc_log
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import CompositeMetaClass
|
||||
|
||||
@@ -36,8 +35,8 @@ class PlayerTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if p.paused and server.id in pause_times:
|
||||
try:
|
||||
await p.pause(False)
|
||||
except Exception as err:
|
||||
debug_exc_log(log, err, "Exception raised in Audio's unpausing %r.", p)
|
||||
except Exception as exc:
|
||||
log.debug("Exception raised in Audio's unpausing %r.", p, exc_info=exc)
|
||||
pause_times.pop(server.id, None)
|
||||
servers = stop_times.copy()
|
||||
servers.update(pause_times)
|
||||
@@ -55,9 +54,9 @@ class PlayerTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
await self.config.guild_from_id(
|
||||
guild_id=sid
|
||||
).currently_auto_playing_in.set([])
|
||||
except Exception as err:
|
||||
debug_exc_log(
|
||||
log, err, "Exception raised in Audio's emptydc_timer for %s.", sid
|
||||
except Exception as exc:
|
||||
log.debug(
|
||||
"Exception raised in Audio's emptydc_timer for %s.", sid, exc_info=exc
|
||||
)
|
||||
|
||||
elif sid in stop_times and await self.config.guild(server_obj).emptydc_enabled():
|
||||
@@ -73,11 +72,13 @@ class PlayerTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
await self.config.guild_from_id(
|
||||
guild_id=sid
|
||||
).currently_auto_playing_in.set([])
|
||||
except Exception as err:
|
||||
if "No such player for that guild" in str(err):
|
||||
except Exception as exc:
|
||||
if "No such player for that guild" in str(exc):
|
||||
stop_times.pop(sid, None)
|
||||
debug_exc_log(
|
||||
log, err, "Exception raised in Audio's emptydc_timer for %s.", sid
|
||||
log.debug(
|
||||
"Exception raised in Audio's emptydc_timer for %s.",
|
||||
sid,
|
||||
exc_info=exc,
|
||||
)
|
||||
elif (
|
||||
sid in pause_times and await self.config.guild(server_obj).emptypause_enabled()
|
||||
@@ -86,10 +87,10 @@ class PlayerTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if (time.time() - pause_times.get(sid, 0)) >= emptypause_timer:
|
||||
try:
|
||||
await lavalink.get_player(sid).pause()
|
||||
except Exception as err:
|
||||
if "No such player for that guild" in str(err):
|
||||
except Exception as exc:
|
||||
if "No such player for that guild" in str(exc):
|
||||
pause_times.pop(sid, None)
|
||||
debug_exc_log(
|
||||
log, err, "Exception raised in Audio's pausing for %s.", sid
|
||||
log.debug(
|
||||
"Exception raised in Audio's pausing for %s.", sid, exc_info=exc
|
||||
)
|
||||
await asyncio.sleep(5)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
import itertools
|
||||
import logging
|
||||
from pathlib import Path
|
||||
@@ -11,16 +10,14 @@ import lavalink
|
||||
from redbot.core.data_manager import cog_data_path
|
||||
from redbot.core.i18n import Translator
|
||||
from redbot.core.utils import AsyncIter
|
||||
from redbot.core.utils._internal_utils import send_to_owners_with_prefix_replaced
|
||||
from redbot.core.utils.dbtools import APSWConnectionWrapper
|
||||
|
||||
from ...apis.interface import AudioAPIInterface
|
||||
from ...apis.playlist_wrapper import PlaylistWrapper
|
||||
from ...audio_logging import debug_exc_log
|
||||
from ...errors import DatabaseError, TrackEnqueueError
|
||||
from ...utils import task_callback
|
||||
from ...utils import task_callback_debug
|
||||
from ..abc import MixinMeta
|
||||
from ..cog_utils import _OWNER_NOTIFICATION, _SCHEMA_VERSION, CompositeMetaClass
|
||||
from ..cog_utils import _SCHEMA_VERSION, CompositeMetaClass
|
||||
|
||||
log = logging.getLogger("red.cogs.Audio.cog.Tasks.startup")
|
||||
_ = Translator("Audio", Path(__file__))
|
||||
@@ -33,7 +30,7 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
# as initial load happens before the bot can ever be ready.
|
||||
lavalink.set_logging_level(self.bot._cli_flags.logging_level)
|
||||
self.cog_init_task = self.bot.loop.create_task(self.initialize())
|
||||
self.cog_init_task.add_done_callback(task_callback)
|
||||
self.cog_init_task.add_done_callback(task_callback_debug)
|
||||
|
||||
async def initialize(self) -> None:
|
||||
await self.bot.wait_until_red_ready()
|
||||
@@ -59,21 +56,21 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
self.player_automated_timer_task = self.bot.loop.create_task(
|
||||
self.player_automated_timer()
|
||||
)
|
||||
self.player_automated_timer_task.add_done_callback(task_callback)
|
||||
except Exception as err:
|
||||
log.exception("Audio failed to start up, please report this issue.", exc_info=err)
|
||||
raise err
|
||||
self.player_automated_timer_task.add_done_callback(task_callback_debug)
|
||||
except Exception as exc:
|
||||
log.critical("Audio failed to start up, please report this issue.", exc_info=exc)
|
||||
return
|
||||
|
||||
self.cog_ready_event.set()
|
||||
|
||||
async def restore_players(self):
|
||||
tries = 0
|
||||
tracks_to_restore = await self.api_interface.persistent_queue_api.fetch_all()
|
||||
while not lavalink.node._nodes:
|
||||
while not lavalink.get_all_nodes():
|
||||
await asyncio.sleep(1)
|
||||
tries += 1
|
||||
if tries > 60:
|
||||
log.exception("Unable to restore players, couldn't connect to Lavalink.")
|
||||
log.warning("Unable to restore players, couldn't connect to Lavalink.")
|
||||
return
|
||||
metadata = {}
|
||||
all_guilds = await self.config.all_guilds()
|
||||
@@ -136,8 +133,8 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
tries += 1
|
||||
except Exception as exc:
|
||||
tries += 1
|
||||
debug_exc_log(
|
||||
log, exc, "Failed to restore music voice channel %s", vc_id
|
||||
log.debug(
|
||||
"Failed to restore music voice channel %s", vc_id, exc_info=exc
|
||||
)
|
||||
if vc is None:
|
||||
break
|
||||
@@ -159,9 +156,9 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
player.maybe_shuffle()
|
||||
if not player.is_playing:
|
||||
await player.play()
|
||||
log.info("Restored %r", player)
|
||||
except Exception as err:
|
||||
debug_exc_log(log, err, "Error restoring player in %d", guild_id)
|
||||
log.debug("Restored %r", player)
|
||||
except Exception as exc:
|
||||
log.debug("Error restoring player in %d", guild_id, exc_info=exc)
|
||||
await self.api_interface.persistent_queue_api.drop(guild_id)
|
||||
|
||||
for guild_id, (notify_channel_id, vc_id) in metadata.items():
|
||||
@@ -205,7 +202,7 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
tries += 1
|
||||
except Exception as exc:
|
||||
tries += 1
|
||||
debug_exc_log(log, exc, "Failed to restore music voice channel %s", vc_id)
|
||||
log.debug("Failed to restore music voice channel %s", vc_id, exc_info=exc)
|
||||
if vc is None:
|
||||
break
|
||||
else:
|
||||
@@ -219,7 +216,7 @@ class StartUpTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
if player.volume != volume:
|
||||
await player.set_volume(volume)
|
||||
player.maybe_shuffle()
|
||||
log.info("Restored %r", player)
|
||||
log.debug("Restored %r", player)
|
||||
if not player.is_playing:
|
||||
notify_channel = player.fetch("notify_channel")
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user