Skip to content

Commit ce586bc

Browse files
committed
fix: ignore invalid partInstances during syncChangesToPartInstances
1 parent 51b69f9 commit ce586bc

File tree

1 file changed

+74
-58
lines changed

1 file changed

+74
-58
lines changed

packages/job-worker/src/ingest/syncChangesToPartInstance.ts

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -267,70 +267,86 @@ export function findInstancesToSync(
267267

268268
const instancesToSync: PartInstanceToSync[] = []
269269
if (currentPartInstance) {
270-
// If the currentPartInstance is adlibbed we probably also need to find the earliest
271-
// non-adlibbed Part within this segment and check it for updates too. It may have something
272-
// changed (like timing) that will affect what's going on.
273-
// The previous "planned" Part Instance needs to be inserted into the `instances` first, so that
274-
// it's ran first through the blueprints.
275-
if (currentPartInstance.partInstance.orphaned === 'adlib-part') {
276-
const partAndPartInstance = findLastUnorphanedPartInstanceInSegment(
277-
playoutModel,
278-
currentPartInstance.partInstance
279-
)
280-
if (partAndPartInstance) {
281-
const lastPartRundownModel = findPlayoutRundownModel(
282-
playoutRundownModel,
283-
playoutModel,
284-
partAndPartInstance.partInstance.partInstance.part.rundownId
285-
)
286-
287-
insertToSyncedInstanceCandidates(
288-
context,
289-
instancesToSync,
270+
try {
271+
// If the currentPartInstance is adlibbed we probably also need to find the earliest
272+
// non-adlibbed Part within this segment and check it for updates too. It may have something
273+
// changed (like timing) that will affect what's going on.
274+
// The previous "planned" Part Instance needs to be inserted into the `instances` first, so that
275+
// it's ran first through the blueprints.
276+
if (currentPartInstance.partInstance.orphaned === 'adlib-part') {
277+
const partAndPartInstance = findLastUnorphanedPartInstanceInSegment(
290278
playoutModel,
291-
lastPartRundownModel,
292-
ingestModel,
293-
partAndPartInstance.partInstance,
294-
null,
295-
partAndPartInstance.part,
296-
'previous'
279+
currentPartInstance.partInstance
297280
)
281+
if (partAndPartInstance) {
282+
try {
283+
const lastPartRundownModel = findPlayoutRundownModel(
284+
playoutRundownModel,
285+
playoutModel,
286+
partAndPartInstance.partInstance.partInstance.part.rundownId
287+
)
288+
289+
insertToSyncedInstanceCandidates(
290+
context,
291+
instancesToSync,
292+
playoutModel,
293+
lastPartRundownModel,
294+
ingestModel,
295+
partAndPartInstance.partInstance,
296+
null,
297+
partAndPartInstance.part,
298+
'previous'
299+
)
300+
} catch (err) {
301+
logger.error(
302+
`Failed to prepare previousPartInstance for syncChangesToPartInstances: ${stringifyError(
303+
err
304+
)}`
305+
)
306+
}
307+
}
298308
}
299-
}
300309

301-
// We can now run the current Part Instance.
302-
const currentPartRundownModel = findPlayoutRundownModel(
303-
playoutRundownModel,
304-
playoutModel,
305-
currentPartInstance.partInstance.part.rundownId
306-
)
307-
findPartAndInsertToSyncedInstanceCandidates(
308-
context,
309-
instancesToSync,
310-
playoutModel,
311-
currentPartRundownModel,
312-
ingestModel,
313-
currentPartInstance,
314-
previousPartInstance,
315-
'current'
316-
)
310+
// We can now run the current Part Instance.
311+
const currentPartRundownModel = findPlayoutRundownModel(
312+
playoutRundownModel,
313+
playoutModel,
314+
currentPartInstance.partInstance.part.rundownId
315+
)
316+
findPartAndInsertToSyncedInstanceCandidates(
317+
context,
318+
instancesToSync,
319+
playoutModel,
320+
currentPartRundownModel,
321+
ingestModel,
322+
currentPartInstance,
323+
previousPartInstance,
324+
'current'
325+
)
326+
} catch (err) {
327+
logger.error(`Failed to prepare currentPartInstance for syncChangesToPartInstances: ${stringifyError(err)}`)
328+
}
317329
}
318330
if (nextPartInstance) {
319-
const nextPartRundownModel = findPlayoutRundownModel(
320-
playoutRundownModel,
321-
playoutModel,
322-
nextPartInstance.partInstance.part.rundownId
323-
)
324-
findPartAndInsertToSyncedInstanceCandidates(
325-
context,
326-
instancesToSync,
327-
playoutModel,
328-
nextPartRundownModel,
329-
ingestModel,
330-
nextPartInstance,
331-
currentPartInstance,
332-
currentPartInstance?.isTooCloseToAutonext(false) ? 'current' : 'next'
333-
)
331+
try {
332+
const nextPartRundownModel = findPlayoutRundownModel(
333+
playoutRundownModel,
334+
playoutModel,
335+
nextPartInstance.partInstance.part.rundownId
336+
)
337+
findPartAndInsertToSyncedInstanceCandidates(
338+
context,
339+
instancesToSync,
340+
playoutModel,
341+
nextPartRundownModel,
342+
ingestModel,
343+
nextPartInstance,
344+
currentPartInstance,
345+
currentPartInstance?.isTooCloseToAutonext(false) ? 'current' : 'next'
346+
)
347+
} catch (err) {
348+
logger.error(`Failed to prepare nextPartInstance for syncChangesToPartInstances: ${stringifyError(err)}`)
349+
}
334350
}
335351

336352
return instancesToSync

0 commit comments

Comments
 (0)