Use env variables for determining shard count/index

Its a really messy way, but k8s is dumb
This commit is contained in:
NovaFox161
2021-06-14 23:21:25 -05:00
parent 0809f9eba1
commit e31f116f41
7 changed files with 54 additions and 20 deletions

View File

@@ -4,9 +4,9 @@ import discord4j.core.event.domain.message.MessageCreateEvent;
import discord4j.core.object.entity.Guild;
import discord4j.core.spec.EmbedCreateSpec;
import discord4j.rest.util.Image;
import org.dreamexposure.discal.Application;
import org.dreamexposure.discal.client.message.Messages;
import org.dreamexposure.discal.core.database.DatabaseManager;
import org.dreamexposure.discal.core.object.BotSettings;
import org.dreamexposure.discal.core.object.GuildSettings;
import org.dreamexposure.discal.core.object.command.CommandInfo;
import org.dreamexposure.discal.core.utils.ChannelUtils;
@@ -144,7 +144,7 @@ public class DisCalCommand implements Command {
spec.addField(Messages.getMessage("Embed.DisCal.Info.Developer", settings), "DreamExposure", true);
spec.addField(Messages.getMessage("Embed.Discal.Info.Version", settings), GlobalConst.version, true);
spec.addField(Messages.getMessage("Embed.DisCal.Info.Library", settings), GlobalConst.d4jVersion, false);
spec.addField("Shard Index", BotSettings.SHARD_INDEX.get() + "/" + BotSettings.SHARD_COUNT.get(), true);
spec.addField("Shard Index", Application.getShardIndex() + "/" + Application.getShardCount(), true);
spec.addField(Messages.getMessage("Embed.DisCal.Info.TotalGuilds", settings), guilds, true);
spec.addField(Messages.getMessage("Embed.DisCal.Info.TotalCalendars", settings), calendars, true);
spec.addField(Messages.getMessage("Embed.DisCal.Info.TotalAnnouncements", settings), announcements, true);

View File

@@ -2,9 +2,9 @@ package org.dreamexposure.discal.client.module.misc;
import discord4j.core.object.presence.Activity;
import discord4j.core.object.presence.Presence;
import org.dreamexposure.discal.Application;
import org.dreamexposure.discal.client.DisCalClient;
import org.dreamexposure.discal.core.database.DatabaseManager;
import org.dreamexposure.discal.core.object.BotSettings;
import org.dreamexposure.discal.core.utils.GlobalConst;
import java.util.ArrayList;
@@ -45,7 +45,7 @@ public class StatusChanger extends TimerTask {
status = status.replace("%guCount%", DisCalClient.getClient().getGuilds().count().block() + "");
status = status.replace("%calCount%", DatabaseManager.INSTANCE.getCalendarCount().block() + "");
status = status.replace("%annCount%", DatabaseManager.INSTANCE.getAnnouncementCount().block() + "");
status = status.replace("%shards%", BotSettings.SHARD_COUNT.get());
status = status.replace("%shards%", Application.getShardCount() + "");
DisCalClient.getClient().updatePresence(Presence.online(Activity.playing(status))).subscribe();
//Set new index.

View File

@@ -3,6 +3,7 @@ package org.dreamexposure.discal.client.service;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import org.dreamexposure.discal.Application;
import org.dreamexposure.discal.client.DisCalClient;
import org.dreamexposure.discal.core.logger.LogFeed;
import org.dreamexposure.discal.core.logger.object.LogObject;
@@ -35,7 +36,7 @@ public class KeepAliveHandler {
public void run() {
try {
final JSONObject data = new JSONObject();
data.put("index", Integer.parseInt(BotSettings.SHARD_INDEX.get()));
data.put("index", Application.getShardIndex());
if (DisCalClient.getClient() != null)
data.put("guilds", DisCalClient.getClient().getGuilds().count().block());

View File

@@ -157,8 +157,8 @@ class DisCalClient {
private fun getStrategy(): ShardingStrategy {
return ShardingStrategy.builder()
.count(BotSettings.SHARD_COUNT.get().toInt())
.indices(BotSettings.SHARD_INDEX.get().toInt())
.count(Application.getShardCount())
.indices(Application.getShardIndex().toInt())
.build()
}