Skip to content

Commit

Permalink
fix: add shard information to stats command and
Browse files Browse the repository at this point in the history
optimize clusterCreate event
  • Loading branch information
dev-737 committed Nov 22, 2023
1 parent 263005e commit 090b6ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/commands/slash/Information/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export default class Stats extends BaseCommand {
.setDescription(
stripIndents`
### Shard Stats
**Total Shards:** ${interaction.client.cluster.info.TOTAL_SHARDS}
**Total Shards:** ${interaction.client.cluster.info.TOTAL_SHARDS}
**On Shard:** ${interaction.guild?.shardId}
`,
)
.setFields(
Expand Down
22 changes: 12 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ const processAndManageBlacklists = async (
};

manager.on('clusterCreate', async (cluster) => {
const scheduler = new Scheduler();
// remove expired blacklists or set new timers for them
const serverQuery = { where: { hubs: { some: { expires: { isSet: true } } } } };
const userQuery = { where: { blacklistedFrom: { some: { expires: { isSet: true } } } } };
processAndManageBlacklists(await db.blacklistedServers.findMany(serverQuery), scheduler);
processAndManageBlacklists(await db.userData.findMany(userQuery), scheduler);
// if it is the last cluster
if (cluster.id === manager.totalClusters - 1) {
const scheduler = new Scheduler();
// remove expired blacklists or set new timers for them
const serverQuery = { where: { hubs: { some: { expires: { isSet: true } } } } };
const userQuery = { where: { blacklistedFrom: { some: { expires: { isSet: true } } } } };
processAndManageBlacklists(await db.blacklistedServers.findMany(serverQuery), scheduler);
processAndManageBlacklists(await db.userData.findMany(userQuery), scheduler);

// if it is the last cluster and code is in production
if (cluster.id === manager.totalClusters - 1 && !isDevBuild) {
// code must be in production to run these tasks
if (!isDevBuild) return;
// give time for shards to connect for these tasks
await wait(10_000);

Expand All @@ -98,9 +100,9 @@ manager.on('clusterCreate', async (cluster) => {

// update top.gg stats every 10 minutes
scheduler.addRecurringTask('syncBotlistStats', 60 * 10_000, syncBotlistStats);
// delete expired invites every hour
// delete expired invites every 1 hour
scheduler.addRecurringTask('deleteExpiredInvites', 60 * 60 * 1_000, deleteExpiredInvites);
// delete old network messages every 12 hours
scheduler.addRecurringTask('deleteOldMessages', 60 * 60 * 12_000, deleteOldMessages); // every 12 hours
scheduler.addRecurringTask('deleteOldMessages', 60 * 60 * 12_000, deleteOldMessages);
}
});

0 comments on commit 090b6ad

Please sign in to comment.