Skip to content

Commit b1045f9

Browse files
committed
fix: set nextPartInstance to null if it's referring to a Segment that has been removed
1 parent 898d8ff commit b1045f9

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ export async function CommitIngestOperation(
224224
const pSaveIngest = ingestModel.saveAllToDatabase()
225225
pSaveIngest.catch(() => null) // Ensure promise isn't reported as unhandled
226226

227+
ensureNextPartInstanceIsNotDeleted(playoutModel)
228+
227229
await validateAdlibTestingSegment(context, playoutModel)
228230

229231
try {
@@ -277,14 +279,18 @@ function canRemoveSegment(
277279
logger.warn(`Not allowing removal of previous playing segment "${segmentId}", making segment unsynced instead`)
278280
return false
279281
}
280-
if (
281-
currentPartInstance?.segmentId === segmentId ||
282-
(nextPartInstance?.segmentId === segmentId && isTooCloseToAutonext(currentPartInstance, false))
283-
) {
282+
if (currentPartInstance?.segmentId === segmentId) {
284283
// Don't allow removing an active rundown
285284
logger.warn(`Not allowing removal of current playing segment "${segmentId}", making segment unsynced instead`)
286285
return false
287286
}
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+
}
288294

289295
if (nextPartInstance?.segmentId === segmentId && nextPartInstance.orphaned === 'adlib-part') {
290296
// Don't allow removing an active rundown
@@ -863,3 +869,12 @@ async function validateAdlibTestingSegment(_context: JobContext, playoutModel: P
863869
rundown.updateAdlibTestingSegmentRank()
864870
}
865871
}
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+
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,13 @@ export async function syncChangesToPartInstances(
157157
existingPartInstance.partInstance._id
158158
)
159159
} catch (e) {
160-
161-
logger.error(`TROUBLESHOOTING: currentPartInstance: ${JSON.stringify(playoutModel.currentPartInstance)}`)
160+
logger.error(
161+
`TROUBLESHOOTING: currentPartInstance: ${JSON.stringify(playoutModel.currentPartInstance)}`
162+
)
162163
logger.error(`TROUBLESHOOTING: nextPartInstance: ${JSON.stringify(playoutModel.nextPartInstance)}`)
163-
logger.error(`TROUBLESHOOTING: previousPartInstance: ${JSON.stringify(playoutModel.previousPartInstance)}`)
164+
logger.error(
165+
`TROUBLESHOOTING: previousPartInstance: ${JSON.stringify(playoutModel.previousPartInstance)}`
166+
)
164167

165168
throw e
166169
}

0 commit comments

Comments
 (0)