Skip to content

Commit

Permalink
Prevent "Start server for nearest mission" job failures if there is n…
Browse files Browse the repository at this point in the history
…o nearest mission (#95)
  • Loading branch information
3Mydlo3 authored Sep 14, 2024
1 parent 4381c46 commit aacded7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ namespace ArmaForces.ArmaServerManager.Features.Missions.Extensions
{
internal static class WebMissionsCollectionExtensions
{
public const string NoNearestMissionError = "No nearest mission found.";

public static Result<WebMission> GetNearestMission(this IEnumerable<WebMission> missions)
{
var nearestMission = missions
.OrderBy(x => x.Date)
.FirstOrDefault();

return nearestMission is null
? Result.Failure<WebMission>("No nearest mission found.")
? Result.Failure<WebMission>(NoNearestMissionError)
: Result.Success(nearestMission);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ public async Task<Result> StartServerForNearestMission(CancellationToken cancell
return await _apiMissionsClient
.GetUpcomingMissions()
.Bind(x => x.GetNearestMission())
.Bind(nearestMission => _serverStartupService.StartServer(nearestMission.Modlist, ServerStartRequestDto.DefaultHeadlessClients, cancellationToken));
.Bind(nearestMission => _serverStartupService.StartServer(nearestMission.Modlist, ServerStartRequestDto.DefaultHeadlessClients, cancellationToken))
.OnFailureCompensate(error => error.Contains(WebMissionsCollectionExtensions.NoNearestMissionError)
? Result.Success()
: Result.Failure(error));
}

private async Task<Result<HashSet<Mod>>> GetModsListFromModsets(IReadOnlyCollection<string> modsetsNames)
Expand Down

0 comments on commit aacded7

Please sign in to comment.