Skip to content

Commit

Permalink
Merge pull request #1360 from nrkno/fix/sofie-3626/better-delete-next…
Browse files Browse the repository at this point in the history
…-partInstance

fix: a better fix for the deleted PartInstance problem
  • Loading branch information
jstarpl authored Jan 20, 2025
2 parents baacf0e + b480cc8 commit ad370c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 46 deletions.
26 changes: 2 additions & 24 deletions packages/job-worker/src/ingest/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { unprotectString, protectString } from '@sofie-automation/corelib/dist/p
import { logger } from '../logging'
import { PlayoutModel } from '../playout/model/PlayoutModel'
import { PlayoutRundownModel } from '../playout/model/PlayoutRundownModel'
import { isTooCloseToAutonext } from '../playout/lib'
import { allowedToMoveRundownOutOfPlaylist } from '../rundown'
import { updatePartInstanceRanksAndOrphanedState } from '../updatePartInstanceRanksAndOrphanedState'
import {
Expand Down Expand Up @@ -224,8 +223,6 @@ export async function CommitIngestOperation(
const pSaveIngest = ingestModel.saveAllToDatabase()
pSaveIngest.catch(() => null) // Ensure promise isn't reported as unhandled

ensureNextPartInstanceIsNotDeleted(playoutModel)

await validateAdlibTestingSegment(context, playoutModel)

try {
Expand Down Expand Up @@ -284,19 +281,9 @@ function canRemoveSegment(
logger.warn(`Not allowing removal of current playing segment "${segmentId}", making segment unsynced instead`)
return false
}
if (nextPartInstance?.segmentId === segmentId && isTooCloseToAutonext(currentPartInstance, false)) {
// Don't allow removing an active rundown
logger.warn(
`Not allowing removal of nexted segment "${segmentId}", because it's too close to an auto-next, making segment unsynced instead`
)
return false
}

if (nextPartInstance?.segmentId === segmentId && nextPartInstance.orphaned === 'adlib-part') {
if (nextPartInstance?.segmentId === segmentId) {
// Don't allow removing an active rundown
logger.warn(
`Not allowing removal of segment "${segmentId}" which contains nexted adlibbed part, making segment unsynced instead`
)
logger.warn(`Not allowing removal of nexted segment "${segmentId}", making segment unsynced instead`)
return false
}

Expand Down Expand Up @@ -855,12 +842,3 @@ async function validateAdlibTestingSegment(_context: JobContext, playoutModel: P
rundown.updateAdlibTestingSegmentRank()
}
}
function ensureNextPartInstanceIsNotDeleted(playoutModel: PlayoutModel) {
if (playoutModel.nextPartInstance) {
// Check if the segment of the nextPartInstance exists
if (!playoutModel.findSegment(playoutModel.nextPartInstance.partInstance.segmentId)) {
// The segment doesn't exist, set nextPartInstance to null, it'll be set by ensureNextPartIsValid() later.
playoutModel.setPartInstanceAsNext(null, false, false)
}
}
}
44 changes: 22 additions & 22 deletions packages/job-worker/src/ingest/updateNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,28 @@ export async function ensureNextPartIsValid(context: JobContext, playoutModel: P
const orderedSegments = playoutModel.getAllOrderedSegments()
const orderedParts = playoutModel.getAllOrderedParts()

if (currentPartInstance && nextPartInstance) {
if (!nextPartInstance || nextPartInstance.partInstance.orphaned === 'deleted') {
// Don't have a nextPart or it has been deleted, so autoselect something
const newNextPart = selectNextPart(
context,
playlist,
currentPartInstance?.partInstance ?? null,
nextPartInstance?.partInstance ?? null,
orderedSegments,
orderedParts
)

if (!newNextPart && !playoutModel.playlist.nextPartInfo) {
// No currently nexted part, and nothing was selected, so nothing to update
span?.end()
return false
}

await setNextPart(context, playoutModel, newNextPart ?? null, false)

span?.end()
return true
} else if (currentPartInstance && nextPartInstance) {
// Check if the part is the same
const newNextPart = selectNextPart(
context,
Expand All @@ -70,27 +91,6 @@ export async function ensureNextPartIsValid(context: JobContext, playoutModel: P
span?.end()
return true
}
} else if (!nextPartInstance || nextPartInstance.partInstance.orphaned === 'deleted') {
// Don't have a nextPart or it has been deleted, so autoselect something
const newNextPart = selectNextPart(
context,
playlist,
currentPartInstance?.partInstance ?? null,
nextPartInstance?.partInstance ?? null,
orderedSegments,
orderedParts
)

if (!newNextPart && !playoutModel.playlist.nextPartInfo) {
// No currently nexted part, and nothing was selected, so nothing to update
span?.end()
return false
}

await setNextPart(context, playoutModel, newNextPart ?? null, false)

span?.end()
return true
}

span?.end()
Expand Down

0 comments on commit ad370c1

Please sign in to comment.