Bump RLL and improve logging (#5044)

* version bump

* - bump RLL
- logging changes
- player.channel.guild->player.guild
- small cleanup around logging changes

* missed one

* here this one too

* Apply suggestions from code review

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* add one missing player log

* missed one

* Format with Black

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
Draper
2021-05-18 23:56:10 +01:00
committed by GitHub
parent c9431f7d90
commit 38da7370ec
19 changed files with 164 additions and 148 deletions

View File

@@ -78,14 +78,16 @@ class GlobalCacheWrapper:
search_response = await r.json(loads=json.loads)
if IS_DEBUG and "x-process-time" in r.headers:
log.debug(
f"GET || Ping {r.headers.get('x-process-time')} || "
f"Status code {r.status} || {query}"
"GET || Ping %s || Status code %d || %s",
r.headers.get("x-process-time"),
r.status,
query,
)
if "tracks" not in search_response:
return {}
return search_response
except Exception as err:
debug_exc_log(log, err, f"Failed to Get query: {api_url}/{query}")
debug_exc_log(log, err, "Failed to Get query: %s/%s", api_url, query)
return {}
async def get_spotify(self, title: str, author: Optional[str]) -> dict:
@@ -108,14 +110,17 @@ class GlobalCacheWrapper:
search_response = await r.json(loads=json.loads)
if IS_DEBUG and "x-process-time" in r.headers:
log.debug(
f"GET/spotify || Ping {r.headers.get('x-process-time')} || "
f"Status code {r.status} || {title} - {author}"
"GET/spotify || Ping %s || Status code %d || %s - %s",
r.headers.get("x-process-time"),
r.status,
title,
author,
)
if "tracks" not in search_response:
return {}
return search_response
except Exception as err:
debug_exc_log(log, err, f"Failed to Get query: {api_url}")
debug_exc_log(log, err, "Failed to Get query: %s", api_url)
return {}
async def post_call(self, llresponse: LoadResult, query: Optional[Query]) -> None:
@@ -142,11 +147,13 @@ class GlobalCacheWrapper:
await r.read()
if IS_DEBUG and "x-process-time" in r.headers:
log.debug(
f"POST || Ping {r.headers.get('x-process-time')} ||"
f" Status code {r.status} || {query}"
"GET || Ping %s || Status code %d || %s",
r.headers.get("x-process-time"),
r.status,
query,
)
except Exception as err:
debug_exc_log(log, err, f"Failed to post query: {query}")
debug_exc_log(log, err, "Failed to post query: %s", query)
await asyncio.sleep(0)
async def update_global(self, llresponse: LoadResult, query: Optional[Query] = None):

View File

@@ -149,7 +149,7 @@ class AudioAPIInterface:
async with self._lock:
if lock_id in self._tasks:
if IS_DEBUG:
log.debug(f"Running database writes for {lock_id} ({lock_author})")
log.debug("Running database writes for %d (%s)", lock_id, lock_author)
try:
tasks = self._tasks[lock_id]
tasks = [self.route_tasks(a, tasks[a]) for a in tasks]
@@ -157,11 +157,11 @@ class AudioAPIInterface:
del self._tasks[lock_id]
except Exception as exc:
debug_exc_log(
log, exc, f"Failed database writes for {lock_id} ({lock_author})"
log, exc, "Failed database writes for %d (%s)", lock_id, lock_author
)
else:
if IS_DEBUG:
log.debug(f"Completed database writes for {lock_id} ({lock_author})")
log.debug("Completed database writes for %d (%s)", lock_id, lock_author)
async def run_all_pending_tasks(self) -> None:
"""Run all pending tasks left in the cache, called on cog_unload."""
@@ -248,7 +248,9 @@ class AudioAPIInterface:
{"track": track_info}
)
except Exception as exc:
debug_exc_log(log, exc, f"Failed to fetch {track_info} from YouTube table")
debug_exc_log(
log, exc, "Failed to fetch %r from YouTube table", track_info
)
if val is None:
try:
@@ -386,7 +388,7 @@ class AudioAPIInterface:
)
except Exception as exc:
debug_exc_log(
log, exc, f"Failed to fetch 'spotify:track:{uri}' from Spotify table"
log, exc, "Failed to fetch 'spotify:track:%s' from Spotify table", uri
)
val = None
else:
@@ -513,7 +515,9 @@ class AudioAPIInterface:
{"track": track_info}
)
except Exception as exc:
debug_exc_log(log, exc, f"Failed to fetch {track_info} from YouTube table")
debug_exc_log(
log, exc, "Failed to fetch %r from YouTube table", track_info
)
should_query_global = globaldb_toggle and query_global and val is None
if should_query_global:
llresponse = await self.global_cache_api.get_spotify(track_name, artist_name)
@@ -621,7 +625,7 @@ class AudioAPIInterface:
):
has_not_allowed = True
if IS_DEBUG:
log.debug(f"Query is not allowed in {ctx.guild} ({ctx.guild.id})")
log.debug("Query is not allowed in %r (%d)", ctx.guild.name, ctx.guild.id)
continue
track_list.append(single_track)
if enqueue:
@@ -640,7 +644,7 @@ class AudioAPIInterface:
player.add(ctx.author, single_track)
self.bot.dispatch(
"red_audio_track_enqueue",
player.channel.guild,
player.guild,
single_track,
ctx.author,
)
@@ -656,7 +660,7 @@ class AudioAPIInterface:
player.add(ctx.author, single_track)
self.bot.dispatch(
"red_audio_track_enqueue",
player.channel.guild,
player.guild,
single_track,
ctx.author,
)
@@ -748,7 +752,7 @@ class AudioAPIInterface:
try:
(val, update) = await self.local_cache_api.youtube.fetch_one({"track": track_info})
except Exception as exc:
debug_exc_log(log, exc, f"Failed to fetch {track_info} from YouTube table")
debug_exc_log(log, exc, "Failed to fetch %r from YouTube table", track_info)
if val is None:
try:
youtube_url = await self.fetch_youtube_query(
@@ -813,11 +817,11 @@ class AudioAPIInterface:
{"query": query_string}
)
except Exception as exc:
debug_exc_log(log, exc, f"Failed to fetch '{query_string}' from Lavalink table")
debug_exc_log(log, exc, "Failed to fetch %r from Lavalink table", query_string)
if val and isinstance(val, dict):
if IS_DEBUG:
log.debug(f"Updating Local Database with {query_string}")
log.debug("Updating Local Database with %r", query_string)
task = ("update", ("lavalink", {"query": query_string}))
self.append_task(ctx, *task)
else:
@@ -851,7 +855,7 @@ class AudioAPIInterface:
valid_global_entry = True
if valid_global_entry:
if IS_DEBUG:
log.debug(f"Querying Global DB api for {query}")
log.debug("Querying Global DB api for %r", query)
results, called_api = results, False
if valid_global_entry:
pass
@@ -870,7 +874,7 @@ class AudioAPIInterface:
valid_global_entry = False
else:
if IS_DEBUG:
log.debug(f"Querying Lavalink api for {query_string}")
log.debug("Querying Lavalink api for %r", query_string)
called_api = True
try:
results = await player.load_tracks(query_string)
@@ -923,13 +927,14 @@ class AudioAPIInterface:
debug_exc_log(
log,
exc,
f"Failed to enqueue write task for '{query_string}' to Lavalink table",
"Failed to enqueue write task for %r to Lavalink table",
query_string,
)
return results, called_api
async def autoplay(self, player: lavalink.Player, playlist_api: PlaylistWrapper):
"""Enqueue a random track."""
autoplaylist = await self.config.guild(player.channel.guild).autoplaylist()
autoplaylist = await self.config.guild(player.guild).autoplaylist()
current_cache_level = CacheLevel(await self.config.cache_level())
cache_enabled = CacheLevel.set_lavalink().is_subset(current_cache_level)
notify_channel_id = player.fetch("channel")
@@ -942,8 +947,8 @@ class AudioAPIInterface:
autoplaylist["scope"],
self.bot,
playlist_api,
player.channel.guild,
player.channel.guild.me,
player.guild,
player.guild.me,
)
tracks = playlist.tracks_obj
except Exception as exc:
@@ -956,9 +961,7 @@ class AudioAPIInterface:
if not tracks:
ctx = namedtuple("Context", "message guild cog")
(results, called_api) = await self.fetch_track(
cast(
commands.Context, ctx(player.channel.guild, player.channel.guild, self.cog)
),
cast(commands.Context, ctx(player.guild, player.guild, self.cog)),
player,
Query.process_input(_TOP_100_US, self.cog.local_folder_current_path),
)
@@ -990,8 +993,7 @@ class AudioAPIInterface:
):
if IS_DEBUG:
log.debug(
"Query is not allowed in "
f"{player.channel.guild} ({player.channel.guild.id})"
"Query is not allowed in %r (%d)", player.guild.name, player.guild.id
)
continue
valid = True
@@ -1000,24 +1002,24 @@ class AudioAPIInterface:
"autoplay": True,
"enqueue_time": int(time.time()),
"vc": player.channel.id,
"requester": player.channel.guild.me.id,
"requester": player.guild.me.id,
}
)
player.add(player.channel.guild.me, track)
player.add(player.guild.me, track)
self.bot.dispatch(
"red_audio_track_auto_play",
player.channel.guild,
player.guild,
track,
player.channel.guild.me,
player.guild.me,
player,
)
if notify_channel_id:
await self.config.guild_from_id(
guild_id=player.channel.guild.id
guild_id=player.guild.id
).currently_auto_playing_in.set([notify_channel_id, player.channel.id])
else:
await self.config.guild_from_id(
guild_id=player.channel.guild.id
guild_id=player.guild.id
).currently_auto_playing_in.set([])
if not player.current:
await player.play()

View File

@@ -102,7 +102,7 @@ class SpotifyWrapper:
async with self.session.request("GET", url, params=params, headers=headers) as r:
data = await r.json(loads=json.loads)
if r.status != 200:
log.debug(f"Issue making GET request to {url}: [{r.status}] {data}")
log.debug("Issue making GET request to %r: [%d] %r", url, r.status, data)
return data
async def update_token(self, new_token: Mapping[str, str]):
@@ -146,7 +146,7 @@ class SpotifyWrapper:
except KeyError:
return None
self.spotify_token = token
log.debug(f"Created a new access token for Spotify: {token}")
log.debug("Created a new access token for Spotify: %s", token)
return self.spotify_token["access_token"]
async def post(
@@ -156,7 +156,7 @@ class SpotifyWrapper:
async with self.session.post(url, data=payload, headers=headers) as r:
data = await r.json(loads=json.loads)
if r.status != 200:
log.debug(f"Issue making POST request to {url}: [{r.status}] {data}")
log.debug("Issue making POST request to %r: [%d] %r", url, r.status, data)
return data
async def make_get_call(self, url: str, params: MutableMapping) -> MutableMapping: