Skip to content

Commit

Permalink
chore: doc and logging for troubleshooting
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Nov 21, 2024
1 parent bdab8c4 commit 93f4b9d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/corelib/src/dataModel/Segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SegmentNote } from './Notes'
export enum SegmentOrphanedReason {
/** Segment is deleted from the NRCS but we still need it */
DELETED = 'deleted',
/** Segment should be hidden, but it is still playing */
/** Blueprints want the Segment to be hidden, but it is still playing so is must not be hidden right now. */
HIDDEN = 'hidden',
/** Segment is owned by playout, and is for AdlibTesting in its rundown */
ADLIB_TESTING = 'adlib-testing',
Expand Down
31 changes: 31 additions & 0 deletions packages/job-worker/src/ingest/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ export async function CommitIngestOperation(
// Ensure any adlibbed parts are updated to follow the segmentId of the previous part
await updateSegmentIdsForAdlibbedPartInstances(context, ingestModel, beforePartMap)

if (data.renamedSegments && data.renamedSegments.size > 0) {
logger.debug(`Renamed segments: ${JSON.stringify(Array.from(data.renamedSegments.entries()))}`)
}
// ensure instances have matching segmentIds with the parts
await updatePartInstancesSegmentIds(context, ingestModel, data.renamedSegments, beforePartMap)

Expand Down Expand Up @@ -397,6 +400,34 @@ async function updatePartInstancesSegmentIds(
}
}
if (writeOps.length) await context.directCollections.PartInstances.bulkWrite(writeOps)

// Double check that there are no parts using the old segment ids:
const oldSegmentIds = Array.from(renameRules.keys())
const [badPartInstances, badParts] = await Promise.all([
await context.directCollections.PartInstances.findFetch({
rundownId: ingestModel.rundownId,
segmentId: { $in: oldSegmentIds },
}),
await context.directCollections.Parts.findFetch({
rundownId: ingestModel.rundownId,
segmentId: { $in: oldSegmentIds },
}),
])
if (badPartInstances.length > 0) {
logger.error(
`updatePartInstancesSegmentIds: Failed to update all PartInstances using old SegmentIds "${JSON.stringify(
oldSegmentIds
)}": ${JSON.stringify(badPartInstances)}, writeOps: ${JSON.stringify(writeOps)}`
)
}

if (badParts.length > 0) {
logger.error(
`updatePartInstancesSegmentIds: Failed to update all Parts using old SegmentIds "${JSON.stringify(
oldSegmentIds
)}": ${JSON.stringify(badParts)}, writeOps: ${JSON.stringify(writeOps)}`
)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/job-worker/src/ingest/model/IngestSegmentModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface IngestSegmentModel extends IngestSegmentModelReadonly {
setOrphaned(orphaned: SegmentOrphanedReason | undefined): void

/**
* Mark this Part as being hidden
* Mark this Segment as being hidden
* @param hidden New hidden state
*/
setHidden(hidden: boolean): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,30 @@ export class PlayoutModelImpl extends PlayoutModelReadonlyImpl implements Playou
if (this.rundownsImpl.find((rd) => rd.AdlibTestingSegmentHasChanged))
logOrThrowError(new Error(`Failed no changes in model assertion, an AdlibTesting Segment has been changed`))

if (
Array.from(this.allPartInstances.values()).find(
(part) => !part || part.partInstanceHasChanges || part.changedPieceInstanceIds().length > 0
)
const changedPartInstances = Array.from(this.allPartInstances.entries()).filter(
([_, partInstance]) =>
!partInstance ||
partInstance.partInstanceHasChanges ||
partInstance.changedPieceInstanceIds().length > 0
)
logOrThrowError(new Error(`Failed no changes in model assertion, a PartInstance has been changed`))

if (changedPartInstances.length > 0) {
logOrThrowError(
new Error(
`Failed no changes in model assertion, PartInstances has been changed: ${JSON.stringify(
changedPartInstances.map(
([id, pi]) =>
`${id}: ` +
(!pi
? 'null'
: `partInstanceHasChanges: ${
pi.partInstanceHasChanges
}, changedPieceInstanceIds: ${JSON.stringify(pi.changedPieceInstanceIds())}`)
)
)}`
)
)
}

if (span) span.end()
}
Expand Down

0 comments on commit 93f4b9d

Please sign in to comment.