mirror of
https://github.com/uhIgnacio/EmoteManager.git
synced 2024-08-15 02:23:13 +00:00
Revert "don't under-report guild counts"
This reverts commit7c353e797b
. Revert "cluster startup no longer depend on the first cluster running" This reverts commit2a73585dfd
.
This commit is contained in:
parent
fc6e32a691
commit
bc0f24d89e
1 changed files with 5 additions and 33 deletions
|
@ -18,20 +18,10 @@ from multiprocessing.shared_memory import ShareableList
|
|||
from discord.ext import commands
|
||||
from bot_bin.stats import BotBinStats
|
||||
|
||||
# The resource tracker unlinks shared memory on shutdown and assumes all processes that share memory
|
||||
# share a parent python process. But this is not necessarily the case: the user might decide to run
|
||||
# each cluster as a systemd unit for example. We don't want a crash of a single cluster to unlink
|
||||
# the shared memory segment, so we stub out the resource tracking process here,
|
||||
# as there's no built in way to disable it.
|
||||
# See https://bugs.python.org/issue38119
|
||||
from multiprocessing import resource_tracker
|
||||
resource_tracker.ensure_running = lambda: None
|
||||
resource_tracker.main = lambda: None
|
||||
|
||||
class Stats(BotBinStats):
|
||||
def __init__(self, bot):
|
||||
super().__init__(bot)
|
||||
|
||||
seq = [0] * self.bot.shard_count if self.is_opener() else None
|
||||
# Use our user ID as part of the shm name
|
||||
# to allow running multiple instances of the bot on the same machine.
|
||||
# The shard count is incorporated to prevent the following situation:
|
||||
|
@ -40,32 +30,15 @@ class Stats(BotBinStats):
|
|||
# - Clusters begin using the old 30-element-long list to store their shard counts,
|
||||
# but because some clusters that haven't restarted yet are still using the old shlist.
|
||||
shm_name = f'emote-manager-{self.bot.user_id}-{self.bot.shard_count}'
|
||||
if self.is_opener():
|
||||
seq = [0] * self.bot.shard_count
|
||||
try:
|
||||
self.shlist = ShareableList(seq, name=shm_name)
|
||||
except FileExistsError:
|
||||
# The file was probably left open from a previous run of the bot,
|
||||
# so let's re-attach and wipe the old data.
|
||||
self.shlist = ShareableList(name=shm_name)
|
||||
# apparently ShareableLists don't support slicing with None values of `stop`
|
||||
self.shlist[:self.bot.shard_count] = seq
|
||||
else:
|
||||
try:
|
||||
self.shlist = ShareableList(name=shm_name)
|
||||
except FileNotFoundError:
|
||||
# looks like we're the first cluster to start up
|
||||
seq = [0] * self.bot.shard_count
|
||||
self.shlist = ShareableList(seq, name=shm_name)
|
||||
|
||||
self.shlist = ShareableList(seq, name=shm_name)
|
||||
self.count()
|
||||
|
||||
def is_opener(self):
|
||||
"""return whether this is the cluster that should open the shared memory"""
|
||||
"""return whether this is the process that should open the shared memory"""
|
||||
return 0 in self.bot.shard_ids
|
||||
|
||||
def is_reporter(self):
|
||||
"""return whether this is the cluster that should report stats to the bot lists"""
|
||||
"""return whether we should report stats to the bot lists"""
|
||||
return self.bot.shard_count - 1 in self.bot.shard_ids
|
||||
|
||||
def cog_unload(self):
|
||||
|
@ -76,8 +49,7 @@ class Stats(BotBinStats):
|
|||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
self.count()
|
||||
all_shards_ready = all(self.shlist)
|
||||
if self.is_reporter() and all_shards_ready:
|
||||
if self.is_reporter():
|
||||
await self.send()
|
||||
|
||||
def count(self):
|
||||
|
|
Loading…
Reference in a new issue