Skip to content

Commit

Permalink
Prevent job if there was no nearest mission
Browse files Browse the repository at this point in the history
  • Loading branch information
3Mydlo3 committed Nov 15, 2023
1 parent 660d59a commit 0d7de42
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 @@ -50,7 +50,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 0d7de42

Please sign in to comment.