Add config option for max shard concurrency
This commit is contained in:
parent
2039a34c16
commit
13e3289c26
@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Myriad.Types;
|
using Myriad.Types;
|
||||||
@ -69,9 +68,10 @@ namespace Myriad.Gateway
|
|||||||
|
|
||||||
await StartShards(concurrency);
|
await StartShards(concurrency);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task StartShards(int concurrency)
|
private async Task StartShards(int concurrency)
|
||||||
{
|
{
|
||||||
|
concurrency = GetActualShardConcurrency(concurrency);
|
||||||
|
|
||||||
var lastTime = DateTimeOffset.UtcNow;
|
var lastTime = DateTimeOffset.UtcNow;
|
||||||
var identifyCalls = 0;
|
var identifyCalls = 0;
|
||||||
|
|
||||||
@ -112,5 +112,13 @@ namespace Myriad.Gateway
|
|||||||
if (EventReceived != null)
|
if (EventReceived != null)
|
||||||
await EventReceived(shard, evt);
|
await EventReceived(shard, evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int GetActualShardConcurrency(int recommendedConcurrency)
|
||||||
|
{
|
||||||
|
if (_gatewaySettings.MaxShardConcurrency == null)
|
||||||
|
return recommendedConcurrency;
|
||||||
|
|
||||||
|
return Math.Min(_gatewaySettings.MaxShardConcurrency.Value, recommendedConcurrency);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,5 +4,6 @@
|
|||||||
{
|
{
|
||||||
public string Token { get; init; }
|
public string Token { get; init; }
|
||||||
public GatewayIntent Intents { get; init; }
|
public GatewayIntent Intents { get; init; }
|
||||||
|
public int? MaxShardConcurrency { get; init; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,5 +11,7 @@ namespace PluralKit.Bot
|
|||||||
// and fall back to the separate default array at the use site :)
|
// and fall back to the separate default array at the use site :)
|
||||||
// This does bind [] as null (therefore default) instead of an empty array, but I can live w/ that.
|
// This does bind [] as null (therefore default) instead of an empty array, but I can live w/ that.
|
||||||
public string[] Prefixes { get; set; }
|
public string[] Prefixes { get; set; }
|
||||||
|
|
||||||
|
public int? MaxShardConcurrency { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,16 +21,21 @@ namespace PluralKit.Bot
|
|||||||
protected override void Load(ContainerBuilder builder)
|
protected override void Load(ContainerBuilder builder)
|
||||||
{
|
{
|
||||||
// Clients
|
// Clients
|
||||||
builder.Register(c => new GatewaySettings
|
builder.Register(c =>
|
||||||
{
|
{
|
||||||
Token = c.Resolve<BotConfig>().Token,
|
var botConfig = c.Resolve<BotConfig>();
|
||||||
Intents = GatewayIntent.Guilds |
|
return new GatewaySettings
|
||||||
GatewayIntent.DirectMessages |
|
{
|
||||||
GatewayIntent.DirectMessageReactions |
|
Token = botConfig.Token,
|
||||||
GatewayIntent.GuildEmojis |
|
MaxShardConcurrency = botConfig.MaxShardConcurrency,
|
||||||
GatewayIntent.GuildMessages |
|
Intents = GatewayIntent.Guilds |
|
||||||
GatewayIntent.GuildWebhooks |
|
GatewayIntent.DirectMessages |
|
||||||
GatewayIntent.GuildMessageReactions
|
GatewayIntent.DirectMessageReactions |
|
||||||
|
GatewayIntent.GuildEmojis |
|
||||||
|
GatewayIntent.GuildMessages |
|
||||||
|
GatewayIntent.GuildWebhooks |
|
||||||
|
GatewayIntent.GuildMessageReactions
|
||||||
|
};
|
||||||
}).AsSelf().SingleInstance();
|
}).AsSelf().SingleInstance();
|
||||||
builder.RegisterType<Cluster>().AsSelf().SingleInstance();
|
builder.RegisterType<Cluster>().AsSelf().SingleInstance();
|
||||||
builder.Register(c => new Myriad.Rest.DiscordApiClient(c.Resolve<BotConfig>().Token, c.Resolve<ILogger>()))
|
builder.Register(c => new Myriad.Rest.DiscordApiClient(c.Resolve<BotConfig>().Token, c.Resolve<ILogger>()))
|
||||||
|
Loading…
Reference in New Issue
Block a user