fix: disconnect all shards when shard manager restarts, don't fetch old timeouts
This commit is contained in:
parent
492283b9c1
commit
0564206bf7
2 changed files with 19 additions and 2 deletions
|
|
@ -115,7 +115,9 @@ public class ShardedGatewayClient(
|
||||||
_logger.Information("Started shard {ShardId}/{ShardCount}", shardIndex, TotalShards);
|
_logger.Information("Started shard {ShardId}/{ShardCount}", shardIndex, TotalShards);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await await Task.WhenAny(tasks);
|
var taskResult = await await Task.WhenAny(tasks);
|
||||||
|
Disconnect();
|
||||||
|
return taskResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ShardIdFor(ulong guildId) => (int)((guildId >> 22) % (ulong)TotalShards);
|
public int ShardIdFor(ulong guildId) => (int)((guildId >> 22) % (ulong)TotalShards);
|
||||||
|
|
@ -136,6 +138,17 @@ public class ShardedGatewayClient(
|
||||||
client.Dispose();
|
client.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Disconnect()
|
||||||
|
{
|
||||||
|
_logger.Information("Disconnecting from Discord");
|
||||||
|
foreach (var shardId in _gatewayClients.Keys)
|
||||||
|
{
|
||||||
|
_logger.Debug("Disposing shard {shardId}", shardId);
|
||||||
|
if (_gatewayClients.Remove(shardId, out var client))
|
||||||
|
client.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private IOptions<DiscordGatewayClientOptions> CloneOptions(
|
private IOptions<DiscordGatewayClientOptions> CloneOptions(
|
||||||
DiscordGatewayClientOptions options,
|
DiscordGatewayClientOptions options,
|
||||||
int shardId
|
int shardId
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,11 @@ public class TimeoutRepository(DatabaseConnection conn) : IDisposable, IAsyncDis
|
||||||
);
|
);
|
||||||
|
|
||||||
public async Task<List<DiscordTimeout>> GetAllAsync() =>
|
public async Task<List<DiscordTimeout>> GetAllAsync() =>
|
||||||
(await conn.QueryAsync<DiscordTimeout>("select * from timeouts order by id")).ToList();
|
(
|
||||||
|
await conn.QueryAsync<DiscordTimeout>(
|
||||||
|
"select * from timeouts where until > now() order by id"
|
||||||
|
)
|
||||||
|
).ToList();
|
||||||
|
|
||||||
public async Task<DiscordTimeout> SetAsync(
|
public async Task<DiscordTimeout> SetAsync(
|
||||||
Snowflake guildId,
|
Snowflake guildId,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue