diff --git a/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs b/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs index 7eb22e09d..140c973b7 100644 --- a/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs +++ b/ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs @@ -68,8 +68,8 @@ public class ReplaceBlockItemsHandler(IDbContextFactory dbContextFact private static Validation MinutesMustBeValid(ReplaceBlockItems request, Block block) => Optional(block) - .Filter(_ => request.Minutes > 0 && request.Minutes % 15 == 0) - .ToValidation("Block Minutes must be a positive multiple of 15"); + .Filter(_ => request.Minutes > 0 && request.Minutes % 15 == 0 && request.Minutes <= 24 * 60) + .ToValidation("Block duration must be between 15 minutes and 24 hours"); private static Validation CollectionTypesMustBeValid(ReplaceBlockItems request, Block block) => request.Items.Map(item => CollectionTypeMustBeValid(item, block)).Sequence().Map(_ => block); diff --git a/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs b/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs index 560e76fcb..4fc038233 100644 --- a/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs +++ b/ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs @@ -56,14 +56,29 @@ public class BlockPlayoutBuilder( BlockPlayoutChangeDetection.RemoveItemAndHistory(playout, playoutItem); } + DateTimeOffset currentTime = start; + foreach (EffectiveBlock effectiveBlock in updatedEffectiveBlocks) { - logger.LogDebug( - "Will schedule block {Block} at {Start}", - effectiveBlock.Block.Name, - effectiveBlock.Start); + if (currentTime < effectiveBlock.Start) + { + currentTime = effectiveBlock.Start; - DateTimeOffset currentTime = effectiveBlock.Start; + logger.LogDebug( + "Will schedule block {Block} at {Start}", + effectiveBlock.Block.Name, + effectiveBlock.Start); + } + else + { + logger.LogDebug( + "Will schedule block {Block} with start {Start} at {ActualStart}", + effectiveBlock.Block.Name, + effectiveBlock.Start, + currentTime); + } + + DateTimeOffset blockFinish = effectiveBlock.Start.AddMinutes(effectiveBlock.Block.Minutes); foreach (BlockItem blockItem in effectiveBlock.Block.Items.OrderBy(i => i.Index)) { @@ -73,6 +88,17 @@ public class BlockPlayoutBuilder( continue; } + if (currentTime >= blockFinish) + { + logger.LogDebug( + "Current time {Time} for block {Block} is beyond block finish {Finish}; will stop with this block's items", + currentTime, + effectiveBlock.Block.Name, + blockFinish); + + break; + } + // check for playout history for this collection string historyKey = HistoryDetails.KeyForBlockItem(blockItem); //logger.LogDebug("History key for block item {Item} is {Key}", blockItem.Id, historyKey);