From cac3ee9bf74de1c07ff5a7020372ea82970efb94 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Sat, 12 Aug 2023 18:47:14 +0500 Subject: [PATCH] Scheduled event update bugfixes (#81) This PR fixes the following bugs in ScheduledEventUpdateService: - When a scheduled event is first added into ScheduledEventData, its status update code will be skipped. This results in some messages not being sent to the EventNotificationChannel - When the status update code returns an unsuccessful Result, the status in ScheduledEventData will still be updated, meaning that the code will not retry. --------- Signed-off-by: Octol1ttle --- src/Data/ScheduledEventData.cs | 4 ++-- src/Services/Update/ScheduledEventUpdateService.cs | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Data/ScheduledEventData.cs b/src/Data/ScheduledEventData.cs index 29075f5..7cd0578 100644 --- a/src/Data/ScheduledEventData.cs +++ b/src/Data/ScheduledEventData.cs @@ -8,12 +8,12 @@ namespace Boyfriend.Data; /// This information is stored on disk as a JSON file. public sealed class ScheduledEventData { - public ScheduledEventData(GuildScheduledEventStatus status) + public ScheduledEventData(GuildScheduledEventStatus? status) { Status = status; } public bool EarlyNotificationSent { get; set; } public DateTimeOffset? ActualStartTime { get; set; } - public GuildScheduledEventStatus Status { get; set; } + public GuildScheduledEventStatus? Status { get; set; } } diff --git a/src/Services/Update/ScheduledEventUpdateService.cs b/src/Services/Update/ScheduledEventUpdateService.cs index 83094e9..3d57f09 100644 --- a/src/Services/Update/ScheduledEventUpdateService.cs +++ b/src/Services/Update/ScheduledEventUpdateService.cs @@ -68,7 +68,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService { if (!data.ScheduledEvents.ContainsKey(scheduledEvent.ID.Value)) { - data.ScheduledEvents.Add(scheduledEvent.ID.Value, new ScheduledEventData(scheduledEvent.Status)); + data.ScheduledEvents.Add(scheduledEvent.ID.Value, new ScheduledEventData(null)); } var storedEvent = data.ScheduledEvents[scheduledEvent.ID.Value]; @@ -79,9 +79,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService continue; } - storedEvent.Status = scheduledEvent.Status; - - var statusChangedResponseResult = storedEvent.Status switch + var statusChangedResponseResult = scheduledEvent.Status switch { GuildScheduledEventStatus.Scheduled => await SendScheduledEventCreatedMessage(scheduledEvent, data.Settings, ct), @@ -89,6 +87,11 @@ public sealed class ScheduledEventUpdateService : BackgroundService await SendScheduledEventUpdatedMessage(scheduledEvent, data, ct), _ => new ArgumentOutOfRangeError(nameof(scheduledEvent.Status)) }; + if (statusChangedResponseResult.IsSuccess) + { + storedEvent.Status = scheduledEvent.Status; + } + failedResults.AddIfFailed(statusChangedResponseResult); }