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 <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-08-12 18:47:14 +05:00 committed by GitHub
parent f260681b39
commit cac3ee9bf7
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -8,12 +8,12 @@ namespace Boyfriend.Data;
/// <remarks>This information is stored on disk as a JSON file.</remarks> /// <remarks>This information is stored on disk as a JSON file.</remarks>
public sealed class ScheduledEventData public sealed class ScheduledEventData
{ {
public ScheduledEventData(GuildScheduledEventStatus status) public ScheduledEventData(GuildScheduledEventStatus? status)
{ {
Status = status; Status = status;
} }
public bool EarlyNotificationSent { get; set; } public bool EarlyNotificationSent { get; set; }
public DateTimeOffset? ActualStartTime { get; set; } public DateTimeOffset? ActualStartTime { get; set; }
public GuildScheduledEventStatus Status { get; set; } public GuildScheduledEventStatus? Status { get; set; }
} }

View file

@ -68,7 +68,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
{ {
if (!data.ScheduledEvents.ContainsKey(scheduledEvent.ID.Value)) 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]; var storedEvent = data.ScheduledEvents[scheduledEvent.ID.Value];
@ -79,9 +79,7 @@ public sealed class ScheduledEventUpdateService : BackgroundService
continue; continue;
} }
storedEvent.Status = scheduledEvent.Status; var statusChangedResponseResult = scheduledEvent.Status switch
var statusChangedResponseResult = storedEvent.Status switch
{ {
GuildScheduledEventStatus.Scheduled => GuildScheduledEventStatus.Scheduled =>
await SendScheduledEventCreatedMessage(scheduledEvent, data.Settings, ct), await SendScheduledEventCreatedMessage(scheduledEvent, data.Settings, ct),
@ -89,6 +87,11 @@ public sealed class ScheduledEventUpdateService : BackgroundService
await SendScheduledEventUpdatedMessage(scheduledEvent, data, ct), await SendScheduledEventUpdatedMessage(scheduledEvent, data, ct),
_ => new ArgumentOutOfRangeError(nameof(scheduledEvent.Status)) _ => new ArgumentOutOfRangeError(nameof(scheduledEvent.Status))
}; };
if (statusChangedResponseResult.IsSuccess)
{
storedEvent.Status = scheduledEvent.Status;
}
failedResults.AddIfFailed(statusChangedResponseResult); failedResults.AddIfFailed(statusChangedResponseResult);
} }