Skip to content

Commit

Permalink
Catch discord dotnet http exceptions in Schedule service (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
Twinki14 authored Dec 18, 2023
1 parent 46cbce9 commit ec305c3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Miha.Discord/Services/Hosted/GuildEventScheduleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Discord;
using Discord.Addons.Hosting;
using Discord.Addons.Hosting.Util;
using Discord.Net;
using Discord.WebSocket;
using Humanizer;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -53,7 +54,18 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

while (!stoppingToken.IsCancellationRequested)
{
await PostWeeklyScheduleAsync();
try
{
await PostWeeklyScheduleAsync();
}
catch (HttpException e)
{
_logger.LogWarning(e, "Discord dotnet http exception caught, likely caused by rate-limits, waiting a few minutes before continuing");

await Task.Delay(TimeSpan.FromMinutes(3), stoppingToken);

continue;
}

var utcNow = _easternStandardZonedClock.GetCurrentInstant().ToDateTimeUtc();
var nextUtc = _cron.GetNextOccurrence(DateTimeOffset.UtcNow, _easternStandardZonedClock.GetTimeZoneInfo());
Expand Down

0 comments on commit ec305c3

Please sign in to comment.