mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09: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:
parent
e073c5a572
commit
f3da876d6d
1 changed files with 2 additions and 7 deletions
|
@ -34,20 +34,15 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
||||||
protected override async Task ExecuteAsync(CancellationToken ct)
|
protected override async Task ExecuteAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
|
using var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));
|
||||||
var tasks = new List<Task>();
|
|
||||||
|
|
||||||
while (await timer.WaitForNextTickAsync(ct))
|
while (await timer.WaitForNextTickAsync(ct))
|
||||||
{
|
{
|
||||||
var guildIds = _guildData.GetGuildIds();
|
var guildIds = _guildData.GetGuildIds();
|
||||||
|
foreach (var id in guildIds)
|
||||||
tasks.AddRange(guildIds.Select(async id =>
|
|
||||||
{
|
{
|
||||||
var tickResult = await TickScheduledEventsAsync(id, ct);
|
var tickResult = await TickScheduledEventsAsync(id, ct);
|
||||||
_logger.LogResult(tickResult, $"Error in scheduled events update for guild {id}.");
|
_logger.LogResult(tickResult, $"Error in scheduled events update for guild {id}.");
|
||||||
}));
|
}
|
||||||
|
|
||||||
await Task.WhenAll(tasks);
|
|
||||||
tasks.Clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue