@@ -180,9 +180,13 @@ export async function CommitIngestOperation(
180
180
// Ensure any adlibbed parts are updated to follow the segmentId of the previous part
181
181
await updateSegmentIdsForAdlibbedPartInstances ( context , ingestModel , beforePartMap )
182
182
183
+ // TODO: This whole section can probably be removed later, it's really unneccessary in the grand scheme of
184
+ // things, it's here only to debug some problems
183
185
if ( data . renamedSegments && data . renamedSegments . size > 0 ) {
184
- logger . debug ( `Renamed segments: ${ JSON . stringify ( Array . from ( data . renamedSegments . entries ( ) ) ) } ` )
186
+ logger . verbose ( `Renamed segments: ${ JSON . stringify ( Array . from ( data . renamedSegments . entries ( ) ) ) } ` )
185
187
}
188
+ // End of temporary section
189
+
186
190
// ensure instances have matching segmentIds with the parts
187
191
await updatePartInstancesSegmentIds ( context , ingestModel , data . renamedSegments , beforePartMap )
188
192
@@ -283,12 +287,9 @@ function canRemoveSegment(
283
287
logger . warn ( `Not allowing removal of current playing segment "${ segmentId } ", making segment unsynced instead` )
284
288
return false
285
289
}
286
-
287
- if ( nextPartInstance ?. segmentId === segmentId && nextPartInstance . orphaned === 'adlib-part' ) {
290
+ if ( nextPartInstance ?. segmentId === segmentId ) {
288
291
// Don't allow removing an active rundown
289
- logger . warn (
290
- `Not allowing removal of segment "${ segmentId } " which contains nexted adlibbed part, making segment unsynced instead`
291
- )
292
+ logger . warn ( `Not allowing removal of nexted segment "${ segmentId } ", making segment unsynced instead` )
292
293
return false
293
294
}
294
295
@@ -367,6 +368,8 @@ async function updatePartInstancesSegmentIds(
367
368
368
369
const writeOps : AnyBulkWriteOperation < DBPartInstance > [ ] = [ ]
369
370
371
+ logger . debug ( `updatePartInstancesSegmentIds: renameRules: ${ JSON . stringify ( renameRules ) } ` )
372
+
370
373
for ( const [ newSegmentId , rule ] of rulesInOrder ) {
371
374
if ( rule . fromSegmentIds . length ) {
372
375
writeOps . push ( {
@@ -404,32 +407,24 @@ async function updatePartInstancesSegmentIds(
404
407
if ( writeOps . length ) await context . directCollections . PartInstances . bulkWrite ( writeOps )
405
408
406
409
// Double check that there are no parts using the old segment ids:
407
- const oldSegmentIds = Array . from ( renameRules . keys ( ) )
408
- const [ badPartInstances , badParts ] = await Promise . all ( [
409
- await context . directCollections . PartInstances . findFetch ( {
410
- rundownId : ingestModel . rundownId ,
411
- segmentId : { $in : oldSegmentIds } ,
412
- } ) ,
413
- await context . directCollections . Parts . findFetch ( {
414
- rundownId : ingestModel . rundownId ,
415
- segmentId : { $in : oldSegmentIds } ,
416
- } ) ,
417
- ] )
410
+ // TODO: This whole section can probably be removed later, it's really unneccessary in the grand scheme of
411
+ // things, it's here only to debug some problems
412
+ const oldSegmentIds : SegmentId [ ] = [ ]
413
+ for ( const renameRule of renameRules . values ( ) ) {
414
+ oldSegmentIds . push ( ...renameRule . fromSegmentIds )
415
+ }
416
+ const badPartInstances = await context . directCollections . PartInstances . findFetch ( {
417
+ rundownId : ingestModel . rundownId ,
418
+ segmentId : { $in : oldSegmentIds } ,
419
+ } )
418
420
if ( badPartInstances . length > 0 ) {
419
421
logger . error (
420
422
`updatePartInstancesSegmentIds: Failed to update all PartInstances using old SegmentIds "${ JSON . stringify (
421
423
oldSegmentIds
422
424
) } ": ${ JSON . stringify ( badPartInstances ) } , writeOps: ${ JSON . stringify ( writeOps ) } `
423
425
)
424
426
}
425
-
426
- if ( badParts . length > 0 ) {
427
- logger . error (
428
- `updatePartInstancesSegmentIds: Failed to update all Parts using old SegmentIds "${ JSON . stringify (
429
- oldSegmentIds
430
- ) } ": ${ JSON . stringify ( badParts ) } , writeOps: ${ JSON . stringify ( writeOps ) } `
431
- )
432
- }
427
+ // End of the temporary section
433
428
}
434
429
}
435
430
@@ -664,10 +659,27 @@ async function getSelectedPartInstances(
664
659
} )
665
660
: [ ]
666
661
662
+ const currentPartInstance = instances . find ( ( inst ) => inst . _id === playlist . currentPartInfo ?. partInstanceId )
663
+ const nextPartInstance = instances . find ( ( inst ) => inst . _id === playlist . nextPartInfo ?. partInstanceId )
664
+ const previousPartInstance = instances . find ( ( inst ) => inst . _id === playlist . previousPartInfo ?. partInstanceId )
665
+
666
+ if ( playlist . currentPartInfo ?. partInstanceId && ! currentPartInstance )
667
+ logger . error (
668
+ `playlist.currentPartInfo is set, but PartInstance "${ playlist . currentPartInfo ?. partInstanceId } " was not found!`
669
+ )
670
+ if ( playlist . nextPartInfo ?. partInstanceId && ! nextPartInstance )
671
+ logger . error (
672
+ `playlist.nextPartInfo is set, but PartInstance "${ playlist . nextPartInfo ?. partInstanceId } " was not found!`
673
+ )
674
+ if ( playlist . previousPartInfo ?. partInstanceId && ! previousPartInstance )
675
+ logger . error (
676
+ `playlist.previousPartInfo is set, but PartInstance "${ playlist . previousPartInfo ?. partInstanceId } " was not found!`
677
+ )
678
+
667
679
return {
668
- currentPartInstance : instances . find ( ( inst ) => inst . _id === playlist . currentPartInfo ?. partInstanceId ) ,
669
- nextPartInstance : instances . find ( ( inst ) => inst . _id === playlist . nextPartInfo ?. partInstanceId ) ,
670
- previousPartInstance : instances . find ( ( inst ) => inst . _id === playlist . previousPartInfo ?. partInstanceId ) ,
680
+ currentPartInstance,
681
+ nextPartInstance,
682
+ previousPartInstance,
671
683
}
672
684
}
673
685
@@ -831,6 +843,16 @@ async function removeSegments(
831
843
} )
832
844
}
833
845
for ( const segmentId of purgeSegmentIds ) {
846
+ logger . debug (
847
+ `IngestModel: Removing segment "${ segmentId } " (` +
848
+ `previousPartInfo?.partInstanceId: ${ newPlaylist . previousPartInfo ?. partInstanceId } ,` +
849
+ `currentPartInfo?.partInstanceId: ${ newPlaylist . currentPartInfo ?. partInstanceId } ,` +
850
+ `nextPartInfo?.partInstanceId: ${ newPlaylist . nextPartInfo ?. partInstanceId } ,` +
851
+ `previousPartInstance.segmentId: ${ ! previousPartInstance ? 'N/A' : previousPartInstance . segmentId } ,` +
852
+ `currentPartInstance.segmentId: ${ ! currentPartInstance ? 'N/A' : currentPartInstance . segmentId } ,` +
853
+ `nextPartInstance.segmentId: ${ ! nextPartInstance ? 'N/A' : nextPartInstance . segmentId } ` +
854
+ `)`
855
+ )
834
856
ingestModel . removeSegment ( segmentId )
835
857
}
836
858
}
0 commit comments