Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade packages & catch exceptions in GuildEventMonitorService loop #75

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Miha.Discord/Miha.Discord.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<ItemGroup>
<PackageReference Include="Cronos" Version="0.8.4" />
<PackageReference Include="Discord.Addons.Hosting" Version="6.1.0" />
<PackageReference Include="Discord.Net" Version="3.15.2" />
<PackageReference Include="Discord.Net" Version="3.16.0" />
<PackageReference Include="Humanizer" Version="2.14.1" />
<PackageReference Include="SlimMessageBus" Version="2.0.2" />
<PackageReference Include="SlimMessageBus.Host.Memory" Version="2.3.5" />
<PackageReference Include="SlimMessageBus" Version="2.0.4" />
<PackageReference Include="SlimMessageBus.Host.Memory" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
Expand Down
35 changes: 22 additions & 13 deletions src/Miha.Discord/Services/Hosted/GuildEventMonitorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,37 @@ public partial class GuildEventMonitorService(
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Waiting for client to be ready...");

await Client.WaitForReadyAsync(stoppingToken);

while (!stoppingToken.IsCancellationRequested)
{
await CheckScheduledEventsAsync();
try
{
await CheckScheduledEventsAsync();

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

if (nextUtc is null)
{
_logger.LogWarning("Next utc occurence is null");
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
continue;
}

var next = nextUtc.Value - utcNow;

var utcNow = easternStandardZonedClock.GetCurrentInstant().ToDateTimeUtc();
var nextUtc = _cron.GetNextOccurrence(DateTimeOffset.UtcNow, easternStandardZonedClock.GetTimeZoneInfo());
_logger.LogDebug("Waiting {Time} until next operation", next.Humanize(3));

if (nextUtc is null)
await Task.Delay(nextUtc.Value - utcNow, stoppingToken);
}
catch (Exception e)
{
_logger.LogWarning("Next utc occurence is null");
_logger.LogError(e, "Exception encountered in GuildEventMonitorService");

await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
continue;
}

var next = nextUtc.Value - utcNow;

_logger.LogDebug("Waiting {Time} until next operation", next.Humanize(3));

await Task.Delay(nextUtc.Value - utcNow, stoppingToken);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Miha.Logic/Miha.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Discord.Addons.Hosting" Version="6.1.0" />
<PackageReference Include="Discord.Net" Version="3.15.2" />
<PackageReference Include="Discord.Net" Version="3.16.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Miha.Redis/Miha.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="FluentResults" Version="3.16.0" />
<PackageReference Include="FluentResults.Extensions.FluentAssertions" Version="2.1.2" />
<PackageReference Include="Redis.OM" Version="0.7.1" />
<PackageReference Include="Redis.OM" Version="0.7.4" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Miha.Shared/Miha.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="NodaTime" Version="3.1.11" />
<PackageReference Include="NodaTime" Version="3.1.12" />
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.2.0" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="TimeZoneConverter" Version="6.1.0" />
</ItemGroup>
Expand Down