@@ -224,6 +224,8 @@ export async function CommitIngestOperation(
224
224
const pSaveIngest = ingestModel . saveAllToDatabase ( )
225
225
pSaveIngest . catch ( ( ) => null ) // Ensure promise isn't reported as unhandled
226
226
227
+ ensureNextPartInstanceIsNotDeleted ( playoutModel )
228
+
227
229
await validateAdlibTestingSegment ( context , playoutModel )
228
230
229
231
try {
@@ -277,14 +279,18 @@ function canRemoveSegment(
277
279
logger . warn ( `Not allowing removal of previous playing segment "${ segmentId } ", making segment unsynced instead` )
278
280
return false
279
281
}
280
- if (
281
- currentPartInstance ?. segmentId === segmentId ||
282
- ( nextPartInstance ?. segmentId === segmentId && isTooCloseToAutonext ( currentPartInstance , false ) )
283
- ) {
282
+ if ( currentPartInstance ?. segmentId === segmentId ) {
284
283
// Don't allow removing an active rundown
285
284
logger . warn ( `Not allowing removal of current playing segment "${ segmentId } ", making segment unsynced instead` )
286
285
return false
287
286
}
287
+ if ( nextPartInstance ?. segmentId === segmentId && isTooCloseToAutonext ( currentPartInstance , false ) ) {
288
+ // Don't allow removing an active rundown
289
+ logger . warn (
290
+ `Not allowing removal of nexted segment "${ segmentId } ", because it's too close to an auto-next, making segment unsynced instead`
291
+ )
292
+ return false
293
+ }
288
294
289
295
if ( nextPartInstance ?. segmentId === segmentId && nextPartInstance . orphaned === 'adlib-part' ) {
290
296
// Don't allow removing an active rundown
@@ -863,3 +869,12 @@ async function validateAdlibTestingSegment(_context: JobContext, playoutModel: P
863
869
rundown . updateAdlibTestingSegmentRank ( )
864
870
}
865
871
}
872
+ function ensureNextPartInstanceIsNotDeleted ( playoutModel : PlayoutModel ) {
873
+ if ( playoutModel . nextPartInstance ) {
874
+ // Check if the segment of the nextPartInstance exists
875
+ if ( ! playoutModel . findSegment ( playoutModel . nextPartInstance . partInstance . segmentId ) ) {
876
+ // The segment doesn't exist, set nextPartInstance to null, it'll be set by ensureNextPartIsValid() later.
877
+ playoutModel . setPartInstanceAsNext ( null , false , false )
878
+ }
879
+ }
880
+ }
0 commit comments