1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 00:19:00 +03:00

Run scheduled event updates synchronously to avoid a rate limit error (#132)

This PR attempts to fix this error:
https://paste.gg/p/anonymous/358d5b1b80b44011b7afe5007270b175 based on
the assumption that the error is caused by a race condition affecting
the rate limit tracking code in Remora.Discord
This commit is contained in:
Octol1ttle 2023-09-30 20:41:46 +05:00 committed by GitHub
parent e073c5a572
commit f3da876d6d
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,20 +34,15 @@ public sealed class ScheduledEventUpdateService : BackgroundService
protected override async Task ExecuteAsync(CancellationToken ct)
{
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
var tasks = new List<Task>();
while (await timer.WaitForNextTickAsync(ct))
{
var guildIds = _guildData.GetGuildIds();
tasks.AddRange(guildIds.Select(async id =>
foreach (var id in guildIds)
{
var tickResult = await TickScheduledEventsAsync(id, ct);
_logger.LogResult(tickResult, $"Error in scheduled events update for guild {id}.");
}));
await Task.WhenAll(tasks);
tasks.Clear();
}
}
}