refactor(bot): ♻️ Replace % with , in logging calls.
This commit is contained in:
+4
-4
@@ -24,7 +24,7 @@ from payphone.core import (
|
|||||||
formatting,
|
formatting,
|
||||||
help_command,
|
help_command,
|
||||||
config,
|
config,
|
||||||
logging
|
logging,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
|
|
||||||
await self.redis.ping()
|
await self.redis.ping()
|
||||||
|
|
||||||
self.log.info("Ready! Logged in as %s." % self.user.display_name)
|
self.log.info("Ready! Logged in as %s.", self.user.display_name)
|
||||||
|
|
||||||
async def on_shard_ready(self, shard_id: int) -> None:
|
async def on_shard_ready(self, shard_id: int) -> None:
|
||||||
"""Sets the activity for the shard.
|
"""Sets the activity for the shard.
|
||||||
@@ -101,7 +101,7 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
shard_id=shard_id,
|
shard_id=shard_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.log.info("Shard %s is ready!" % shard_id)
|
self.log.info("Shard %s is ready!", shard_id)
|
||||||
|
|
||||||
async def on_shard_resumed(self, shard_id: int) -> None:
|
async def on_shard_resumed(self, shard_id: int) -> None:
|
||||||
"""Sets the activity for the shard.
|
"""Sets the activity for the shard.
|
||||||
@@ -118,7 +118,7 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
shard_id=shard_id,
|
shard_id=shard_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.log.info("Shard %s was resumed!" % shard_id)
|
self.log.info("Shard %s was resumed!", shard_id)
|
||||||
|
|
||||||
async def get_or_fetch_channel(
|
async def get_or_fetch_channel(
|
||||||
self, channel_id: int
|
self, channel_id: int
|
||||||
|
|||||||
@@ -79,10 +79,10 @@ async def flush():
|
|||||||
except (
|
except (
|
||||||
asyncpg.exceptions.PostgresError,
|
asyncpg.exceptions.PostgresError,
|
||||||
asyncpg.exceptions.InterfaceError,
|
asyncpg.exceptions.InterfaceError,
|
||||||
) as e:
|
):
|
||||||
log.error(
|
log.exception(
|
||||||
"[Call ID: %s] An error occured trying to flush messages for call ID. %s"
|
"[Call ID: %s] An error occured trying to flush messages for call ID."
|
||||||
% (call_id, e)
|
% call_id
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -96,10 +96,10 @@ async def flush():
|
|||||||
except (
|
except (
|
||||||
asyncpg.exceptions.PostgresError,
|
asyncpg.exceptions.PostgresError,
|
||||||
asyncpg.exceptions.InterfaceError,
|
asyncpg.exceptions.InterfaceError,
|
||||||
) as e:
|
):
|
||||||
log.error(
|
log.exception(
|
||||||
"[Call ID: %s] An error occured trying to flush message contents. %s"
|
"[Call ID: %s] An error occured trying to flush message contents."
|
||||||
% (call_id, e)
|
% call_id
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -127,4 +127,4 @@ async def loop() -> None:
|
|||||||
await flush()
|
await flush()
|
||||||
|
|
||||||
except (KeyboardInterrupt, asyncio.exceptions.CancelledError) as e:
|
except (KeyboardInterrupt, asyncio.exceptions.CancelledError) as e:
|
||||||
log.exception(e)
|
log.exception('')
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ def shard(
|
|||||||
bot.shutdown = shutdown
|
bot.shutdown = shutdown
|
||||||
bot.scheduled_shutdown = scheduled_shutdown
|
bot.scheduled_shutdown = scheduled_shutdown
|
||||||
|
|
||||||
log.info("Running shard %s with default loop." % shard_id)
|
log.info("Running shard %s with default loop.", shard_id)
|
||||||
bot.run(config.TOKEN)
|
bot.run(config.TOKEN)
|
||||||
|
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ if __name__ == "__main__":
|
|||||||
shutdown = manager.Value("b", False)
|
shutdown = manager.Value("b", False)
|
||||||
scheduled_shutdown = manager.Value("b", False)
|
scheduled_shutdown = manager.Value("b", False)
|
||||||
|
|
||||||
log.info("Starting %s shards." % shard_count)
|
log.info("Starting %s shards.", shard_count)
|
||||||
|
|
||||||
ps: list[mp.Process] = [
|
ps: list[mp.Process] = [
|
||||||
mp.Process(
|
mp.Process(
|
||||||
@@ -119,14 +119,12 @@ if __name__ == "__main__":
|
|||||||
for i, p in enumerate(ps):
|
for i, p in enumerate(ps):
|
||||||
p.start()
|
p.start()
|
||||||
|
|
||||||
|
log.info("Shard %s's process started.", i)
|
||||||
log.info(
|
log.info(
|
||||||
f"Shard {i}'s process started."
|
|
||||||
+ (
|
|
||||||
"Waiting 5 seconds start initialize next shard..."
|
"Waiting 5 seconds start initialize next shard..."
|
||||||
if i != len(ps) - 1
|
if i != len(ps) - 1
|
||||||
else "All shards were started."
|
else "All shards were started."
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
if i != len(ps) - 1:
|
if i != len(ps) - 1:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
@@ -144,9 +142,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
for i in range(shard_count):
|
for i in range(shard_count):
|
||||||
if not ps[i].is_alive():
|
if not ps[i].is_alive():
|
||||||
log.warning(
|
log.warning("Shard %s's process exited. Restarting the shard...", i)
|
||||||
"Shard %s's process exited. Restarting the shard..." % s
|
|
||||||
)
|
|
||||||
|
|
||||||
ps[i] = mp.Process(
|
ps[i] = mp.Process(
|
||||||
target=shard,
|
target=shard,
|
||||||
@@ -161,8 +157,8 @@ if __name__ == "__main__":
|
|||||||
ps[i].start()
|
ps[i].start()
|
||||||
|
|
||||||
log.info(
|
log.info(
|
||||||
"Shard %s was restarted. Waiting 5 seconds to check next shard..."
|
"Shard %s was restarted. Waiting 5 seconds to check next shard...",
|
||||||
% i
|
i,
|
||||||
)
|
)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
@@ -183,11 +179,11 @@ if __name__ == "__main__":
|
|||||||
log.info("A shard shut down the bot.")
|
log.info("A shard shut down the bot.")
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
log.info("Terminating %s shards..." % shard_count)
|
log.info("Terminating %s shards...", shard_count)
|
||||||
|
|
||||||
for i, p in enumerate(ps):
|
for i, p in enumerate(ps):
|
||||||
p.terminate()
|
p.terminate()
|
||||||
log.info("Terminated shard %s." % i)
|
log.info("Terminated shard %s.", i)
|
||||||
|
|
||||||
log.info("Stopping messages flushing process...")
|
log.info("Stopping messages flushing process...")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user