Skip to content

Commit 449abf9

Browse files
committed
chore: improve logging, for troubleshooting
1 parent 1330f65 commit 449abf9

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

packages/job-worker/src/playout/infinites.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { SegmentOrphanedReason } from '@sofie-automation/corelib/dist/dataModel/
2323
import { sortRundownIDsInPlaylist } from '@sofie-automation/corelib/dist/playout/playlist'
2424
import { mongoWhere } from '@sofie-automation/corelib/dist/mongo'
2525
import { PlayoutRundownModel } from './model/PlayoutRundownModel'
26+
import { logger } from '../logging'
2627

2728
/** When we crop a piece, set the piece as "it has definitely ended" this far into the future. */
2829
export const DEFINITELY_ENDED_FUTURE_DURATION = 1 * 1000
@@ -330,7 +331,26 @@ export function getPieceInstancesForPart(
330331
if (!playingRundown) throw new Error(`Rundown "${playingPartInstance.partInstance.rundownId}" not found!`)
331332

332333
playingSegment = playingRundown.getSegment(playingPartInstance.partInstance.segmentId)
333-
if (!playingSegment) throw new Error(`Segment "${playingPartInstance.partInstance.segmentId}" not found!`)
334+
if (!playingSegment) {
335+
const rundownId = playingRundown.rundown._id
336+
context.directCollections.Segments.findFetch({
337+
rundownId: rundownId,
338+
})
339+
.then((segment) => {
340+
logger.error(
341+
`TROUBLESHOOT: Segment not found, rundown "${rundownId}", segments in db: ${JSON.stringify(
342+
segment.map((s) => s._id)
343+
)}`
344+
)
345+
})
346+
.catch((e) => logger.error(e))
347+
348+
throw new Error(
349+
`Segment "${playingPartInstance.partInstance.segmentId}" in Rundown "${
350+
playingRundown.rundown._id
351+
}" not found! (other segments: ${JSON.stringify(playingRundown.segments.map((s) => s.segment._id))})`
352+
)
353+
}
334354
}
335355

336356
const segment = rundown.getSegment(part.segmentId)

packages/job-worker/src/playout/model/implementation/LoadPlayoutModel.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { PlayoutModel, PlayoutModelPreInit } from '../PlayoutModel'
2323
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
2424
import { RundownBaselineObj } from '@sofie-automation/corelib/dist/dataModel/RundownBaselineObj'
2525
import { sortRundownsWithinPlaylist } from '@sofie-automation/corelib/dist/playout/playlist'
26+
import { logger } from '../../../logging'
2627

2728
/**
2829
* Load a PlayoutModelPreInit for the given RundownPlaylist
@@ -188,7 +189,7 @@ async function loadRundowns(
188189
context.directCollections.Segments.findFetch({
189190
$or: [
190191
{
191-
// In a different rundown
192+
// Either in rundown when ingestModel === null or not available in ingestModel
192193
rundownId: { $in: loadRundownIds },
193194
},
194195
{
@@ -233,14 +234,25 @@ async function loadRundowns(
233234
}
234235
}
235236

236-
return rundowns.map(
237-
(rundown) =>
238-
new PlayoutRundownModelImpl(
239-
rundown,
240-
groupedSegmentsWithParts.get(rundown._id) ?? [],
241-
groupedBaselineObjects.get(rundown._id) ?? []
237+
return rundowns.map((rundown) => {
238+
const groupedSegmentsWithPartsForRundown = groupedSegmentsWithParts.get(rundown._id)
239+
if (!groupedSegmentsWithPartsForRundown) {
240+
logger.debug(
241+
`groupedSegmentsWithPartsForRundown for Rundown "${rundown._id}" is undefined (has the rundown no segments?)`
242242
)
243-
)
243+
}
244+
const groupedBaselineObjectsForRundown = groupedBaselineObjects.get(rundown._id)
245+
if (!groupedBaselineObjectsForRundown)
246+
logger.debug(
247+
`groupedBaselineObjectsForRundown for Rundown "${rundown._id}" is undefined (has the rundown no baseline objects?)`
248+
)
249+
250+
return new PlayoutRundownModelImpl(
251+
rundown,
252+
groupedSegmentsWithPartsForRundown ?? [],
253+
groupedBaselineObjectsForRundown ?? []
254+
)
255+
})
244256
}
245257

246258
async function loadPartInstances(

0 commit comments

Comments
 (0)