unkept leave now has a configurable delay

This commit is contained in:
Toastie (DCS Team) 2024-08-28 19:57:33 +12:00
parent 7874008da2
commit 1c53371598
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
4 changed files with 15 additions and 15 deletions

View file

@ -42,7 +42,7 @@ public partial class Administration
[Cmd]
[OwnerOnly]
public async Task LeaveUnkeptServers(int shardId = 0)
public async Task LeaveUnkeptServers(int shardId = 0, int delay = 1000)
{
var keptGuildCount = await _svc.GetKeptGuildCount();
@ -58,7 +58,7 @@ public partial class Administration
if (!response)
return;
await _svc.LeaveUnkeptServers(shardId);
await _svc.LeaveUnkeptServers(shardId, delay);
await ctx.OkAsync();
}
}

View file

@ -2,10 +2,8 @@
using LinqToDB.Data;
using LinqToDB.EntityFrameworkCore;
using LinqToDB.Mapping;
using LinqToDB.Tools;
using EllieBot.Common.ModuleBehaviors;
using EllieBot.Db.Models;
using System.Security.Cryptography;
namespace EllieBot.Modules.Administration.DangerousCommands;
@ -14,7 +12,7 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
private TypedKey<KeepReport> _cleanupReportKey = new("cleanup:report");
private TypedKey<bool> _cleanupTriggerKey = new("cleanup:trigger");
private TypedKey<int> _keepTriggerKey = new("keep:trigger");
private TypedKey<(int, int)> _keepTriggerKey = new("keep:trigger");
private readonly IPubSub _pubSub;
private readonly DiscordSocketClient _client;
@ -47,8 +45,10 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
private bool keepTriggered = false;
private async ValueTask InternalTriggerKeep(int shardId)
private async ValueTask InternalTriggerKeep((int shardId, int delay) data)
{
var (shardId, delay) = data;
if (_client.ShardId != shardId)
return;
@ -58,8 +58,6 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
keepTriggered = true;
try
{
await Task.Delay(10 + (10 * _client.ShardId));
var allGuildIds = _client.Guilds.Select(x => x.Id);
HashSet<ulong> dontDelete;
@ -82,8 +80,7 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
if (dontDelete.Contains(guildId))
continue;
// 1 leave per 20 seconds per shard
await Task.Delay(500);
await Task.Delay(delay);
SocketGuild? guild = null;
try
@ -239,8 +236,8 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
return await table.CountAsync();
}
public async Task LeaveUnkeptServers(int shardId)
=> await _pubSub.Pub(_keepTriggerKey, shardId);
public async Task LeaveUnkeptServers(int shardId, int delay)
=> await _pubSub.Pub(_keepTriggerKey, (shardId, delay));
private ValueTask OnKeepReport(KeepReport report)
{

View file

@ -5,5 +5,5 @@ public interface ICleanupService
Task<KeepResult?> DeleteMissingGuildDataAsync();
Task<bool> KeepGuild(ulong guildId);
Task<int> GetKeptGuildCount();
Task LeaveUnkeptServers(int shardId);
Task LeaveUnkeptServers(int shardId, int delay);
}

View file

@ -4562,4 +4562,7 @@ leaveunkeptservers:
ex:
- ''
params:
- { }
- shardId:
desc: "Shard id from which to start leaving unkept servers."
- delay:
desc: "Delay in miliseconds between leaves"