fix(bot): 🐛 p.call and p.skip not warning about scheduled shutdown.
This commit is contained in:
@@ -27,6 +27,19 @@ class Payphone(commands.AutoShardedBot):
|
|||||||
|
|
||||||
This value is shared between shard processes, and if any of them sets this proxy's value to
|
This value is shared between shard processes, and if any of them sets this proxy's value to
|
||||||
`True`, then all shard processes will be terminated by the main process (`run.py`).
|
`True`, then all shard processes will be terminated by the main process (`run.py`).
|
||||||
|
|
||||||
|
To check if the shutdown has been scheduled (but not necessarily is immediately about to
|
||||||
|
occur), use `scheduled_shutdown` instead.
|
||||||
|
"""
|
||||||
|
|
||||||
|
scheduled_shutdown: managers.ValueProxy[bool]
|
||||||
|
"""A value proxy that connects with all other shard processes.
|
||||||
|
|
||||||
|
This value is shared between shard processes, and if any of them sets this proxy's value to
|
||||||
|
`True`, then the bot's shutdown has been started and all shards will be terminated soon.
|
||||||
|
|
||||||
|
To check whether the bot's about to terminate (if the message was sent to the main process) use
|
||||||
|
`shutdown`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
redis: aredis.Redis = aredis.Redis(host="localhost" if config.IS_DEBUG else "redis")
|
redis: aredis.Redis = aredis.Redis(host="localhost" if config.IS_DEBUG else "redis")
|
||||||
|
|||||||
@@ -238,8 +238,8 @@ class Calls(base.Cog):
|
|||||||
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
||||||
)
|
)
|
||||||
+ (
|
+ (
|
||||||
"⚡ The phone will be hung up soon due to a scheduled restart.\n"
|
"⚠️ The phone will be hung up soon due to a scheduled restart.\n"
|
||||||
if self.bot.shutdown.value
|
if self.bot.scheduled_shutdown.value
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
+ msg_phone_answered
|
+ msg_phone_answered
|
||||||
@@ -254,8 +254,8 @@ class Calls(base.Cog):
|
|||||||
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
||||||
)
|
)
|
||||||
+ (
|
+ (
|
||||||
"⚡ The phone will be hung up soon due to a scheduled restart.\n"
|
"⚠️ The phone will be hung up soon due to a scheduled restart.\n"
|
||||||
if self.bot.shutdown.value
|
if self.bot.scheduled_shutdown.value
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -435,8 +435,8 @@ class Calls(base.Cog):
|
|||||||
f"☎️ You skipped the call.\n"
|
f"☎️ You skipped the call.\n"
|
||||||
)
|
)
|
||||||
+ (
|
+ (
|
||||||
"⚡ The phone will be hung up soon due to a scheduled restart.\n"
|
"⚠️ The phone will be hung up soon due to a scheduled restart.\n"
|
||||||
if self.bot.shutdown.value
|
if self.bot.scheduled_shutdown.value
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
+ (
|
+ (
|
||||||
@@ -459,8 +459,8 @@ class Calls(base.Cog):
|
|||||||
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
f"☎️ {secrets.choice(constants.MSGS_PHONE_CALLING)}\n"
|
||||||
)
|
)
|
||||||
+ (
|
+ (
|
||||||
"⚡ The phone will be hung up soon due to a scheduled restart.\n"
|
"⚠️ The phone will be hung up soon due to a scheduled restart.\n"
|
||||||
if self.bot.shutdown.value
|
if self.bot.scheduled_shutdown.value
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -243,6 +243,8 @@ class Mods(base.Cog):
|
|||||||
- `[<reason>]`: The reason of the shutdown.
|
- `[<reason>]`: The reason of the shutdown.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
self.bot.scheduled_shutdown.value = True
|
||||||
|
|
||||||
oncall_channel_ids = list(
|
oncall_channel_ids = list(
|
||||||
await self.bot.redis.smembers(constants.CHANNELS_ONCALL_SET)
|
await self.bot.redis.smembers(constants.CHANNELS_ONCALL_SET)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,13 +3,20 @@ from multiprocessing import managers
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
|
||||||
def shard(shard_id: int, shard_count: int, shutdown: managers.ValueProxy[bool]) -> None:
|
def shard(
|
||||||
|
shard_id: int,
|
||||||
|
shard_count: int,
|
||||||
|
shutdown: managers.ValueProxy[bool],
|
||||||
|
scheduled_shutdown: managers.ValueProxy[bool],
|
||||||
|
) -> None:
|
||||||
"""Starts a new shard.
|
"""Starts a new shard.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
shard_id (int): The shard's ID.
|
shard_id (int): The shard's ID.
|
||||||
shard_count (int): The total amount of shards.
|
shard_count (int): The total amount of shards.
|
||||||
shutdown (ValueProxy[bool]): The flag for the main process to shut down all shards.
|
shutdown (ValueProxy[bool]): The flag for the main process to shut down all shards.
|
||||||
|
scheduled_shutdown (ValueProxy[bool]): The flag for other shards to know the bot's gonna
|
||||||
|
shut down soon.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from payphone.bot import bot
|
from payphone.bot import bot
|
||||||
@@ -18,6 +25,7 @@ def shard(shard_id: int, shard_count: int, shutdown: managers.ValueProxy[bool])
|
|||||||
bot.shard_ids = [shard_id]
|
bot.shard_ids = [shard_id]
|
||||||
bot.shard_count = shard_count
|
bot.shard_count = shard_count
|
||||||
bot.shutdown = shutdown
|
bot.shutdown = shutdown
|
||||||
|
bot.scheduled_shutdown = scheduled_shutdown
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import uvloop # pylint: disable=import-error
|
import uvloop # pylint: disable=import-error
|
||||||
@@ -97,11 +105,12 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
manager = mp.Manager()
|
manager = mp.Manager()
|
||||||
shutdown = manager.Value("b", False)
|
shutdown = manager.Value("b", False)
|
||||||
|
scheduled_shutdown = manager.Value("b", False)
|
||||||
|
|
||||||
print(f"Starting {shard_count} shard{"s" if shard_count != 1 else ""}.")
|
print(f"Starting {shard_count} shard{"s" if shard_count != 1 else ""}.")
|
||||||
|
|
||||||
ps: list[mp.Process] = [
|
ps: list[mp.Process] = [
|
||||||
mp.Process(target=shard, args=(i, shard_count, shutdown))
|
mp.Process(target=shard, args=(i, shard_count, shutdown, scheduled_shutdown))
|
||||||
for i in range(shard_count)
|
for i in range(shard_count)
|
||||||
]
|
]
|
||||||
flushing_p = mp.Process(target=flush_process)
|
flushing_p = mp.Process(target=flush_process)
|
||||||
|
|||||||
Reference in New Issue
Block a user