Skip to content

Commit 335c690

Browse files
committed
feat: Allow blueprints to request that syncIngestUpdateToPartInstance is run
1 parent b2a2225 commit 335c690

7 files changed

Lines changed: 91 additions & 5 deletions

File tree

packages/blueprints-integration/src/context/processIngestDataContext.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import type { IStudioContext } from './studioContext.js'
33
import type { IngestDefaultChangesOptions, MutableIngestRundown, NrcsIngestChangeDetails } from '../ingest.js'
44

55
export interface IProcessIngestDataContext extends IStudioContext {
6+
/**
7+
* Request that `syncIngestUpdateToPartInstance` should be executed for the active PartInstances
8+
* in this ingest operation, even if it would otherwise be skipped.
9+
*
10+
* The request is one-shot and only applies to the current ingest operation.
11+
*/
12+
requestSyncIngestUpdateToPartInstance(): void
13+
614
/**
715
* Perform the default syncing of changes from the ingest data to the rundown.
816
*

packages/job-worker/src/blueprints/context/ProcessIngestDataContext.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ import {
2020
* Custom updates of the IngestRundown are done by calling methods on the mutableIngestRundown itself.
2121
*/
2222
export class ProcessIngestDataContext extends StudioContext implements IProcessIngestDataContext {
23+
#requestSyncIngestUpdateToPartInstance = false
24+
25+
requestSyncIngestUpdateToPartInstance(): void {
26+
this.#requestSyncIngestUpdateToPartInstance = true
27+
}
28+
29+
consumeRequestSyncIngestUpdateToPartInstance(): boolean {
30+
const shouldRequest = this.#requestSyncIngestUpdateToPartInstance
31+
this.#requestSyncIngestUpdateToPartInstance = false
32+
return shouldRequest
33+
}
34+
2335
defaultApplyIngestChanges<TRundownPayload, TSegmentPayload, TPartPayload>(
2436
mutableIngestRundown: MutableIngestRundown<TRundownPayload, TSegmentPayload, TPartPayload>,
2537
nrcsIngestRundown: IngestRundown,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { setupDefaultJobEnvironment } from '../../../__mocks__/context.js'
2+
import { ProcessIngestDataContext } from '../ProcessIngestDataContext.js'
3+
4+
describe('ProcessIngestDataContext', () => {
5+
function createContext(): ProcessIngestDataContext {
6+
const jobContext = setupDefaultJobEnvironment()
7+
8+
return new ProcessIngestDataContext(
9+
{
10+
name: 'test',
11+
identifier: 'test',
12+
},
13+
jobContext.studio,
14+
jobContext.getStudioBlueprintConfig()
15+
)
16+
}
17+
18+
test('requestSyncIngestUpdateToPartInstance is one-shot', () => {
19+
const context = createContext()
20+
21+
expect(context.consumeRequestSyncIngestUpdateToPartInstance()).toBe(false)
22+
23+
context.requestSyncIngestUpdateToPartInstance()
24+
expect(context.consumeRequestSyncIngestUpdateToPartInstance()).toBe(true)
25+
expect(context.consumeRequestSyncIngestUpdateToPartInstance()).toBe(false)
26+
})
27+
28+
test('multiple requests collapse into a single consume result', () => {
29+
const context = createContext()
30+
31+
context.requestSyncIngestUpdateToPartInstance()
32+
context.requestSyncIngestUpdateToPartInstance()
33+
34+
expect(context.consumeRequestSyncIngestUpdateToPartInstance()).toBe(true)
35+
expect(context.consumeRequestSyncIngestUpdateToPartInstance()).toBe(false)
36+
})
37+
})

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,12 @@ export async function CommitIngestOperation(
230230

231231
try {
232232
// sync changes to the 'selected' partInstances
233-
await syncChangesToPartInstances(context, playoutModel, ingestModel)
233+
await syncChangesToPartInstances(
234+
context,
235+
playoutModel,
236+
ingestModel,
237+
data.forceSyncIngestUpdateToPartInstance
238+
)
234239

235240
// update the quickloop in case we did any changes to things involving marker
236241
playoutModel.updateQuickLoopState()

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export interface CommitIngestData {
2525
/** Set to true if the rundown should be removed or orphaned */
2626
removeRundown: boolean
2727

28+
/** Force execution of syncIngestUpdateToPartInstance for this commit operation */
29+
forceSyncIngestUpdateToPartInstance?: boolean
30+
2831
/** Whether to return an error if the rundown is unable to be removed */
2932
returnRemoveFailure?: boolean
3033
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export interface ComputedIngestChangeObject {
5353
regenerateRundown: boolean // Future: full vs metadata?
5454

5555
segmentExternalIdChanges: Record<string, string> // old -> new
56+
57+
/**
58+
* Force an execution of syncIngestUpdateToPartInstance for this ingest operation.
59+
*/
60+
forceSyncIngestUpdateToPartInstance?: boolean
5661
}
5762

5863
export type ComputedIngestChanges = ComputedIngestChangeObject | ComputedIngestChangeAction
@@ -335,12 +340,16 @@ async function updateSofieIngestRundown(
335340

336341
const ingestObjectGenerator = new SofieIngestRundownDataCacheGenerator(rundownId)
337342
const resultChanges = mutableIngestRundown.intoIngestRundown(ingestObjectGenerator)
343+
const forceSyncIngestUpdateToPartInstance = blueprintContext.consumeRequestSyncIngestUpdateToPartInstance()
338344

339345
// Sync changes to the cache
340346
sofieIngestObjectCache.replaceDocuments(resultChanges.changedCacheObjects)
341347
sofieIngestObjectCache.removeAllOtherDocuments(resultChanges.allCacheObjectIds)
342348

343-
return resultChanges.computedChanges
349+
return {
350+
...resultChanges.computedChanges,
351+
forceSyncIngestUpdateToPartInstance,
352+
}
344353
}
345354
}
346355

@@ -438,13 +447,15 @@ async function applyCalculatedIngestChangesToModel(
438447
if (result) {
439448
return {
440449
...result,
450+
forceSyncIngestUpdateToPartInstance: computedIngestChanges.forceSyncIngestUpdateToPartInstance,
441451
renamedSegments,
442452
}
443453
} else {
444454
return {
445455
changedSegmentIds: [],
446456
removedSegmentIds: [],
447457
removeRundown: false,
458+
forceSyncIngestUpdateToPartInstance: computedIngestChanges.forceSyncIngestUpdateToPartInstance,
448459
renamedSegments,
449460
}
450461
}
@@ -480,6 +491,7 @@ async function applyCalculatedIngestChangesToModel(
480491
return {
481492
changedSegmentIds: regeneratedSegmentIds.changedSegmentIds,
482493
removedSegmentIds: regeneratedSegmentIds.removedSegmentIds,
494+
forceSyncIngestUpdateToPartInstance: computedIngestChanges.forceSyncIngestUpdateToPartInstance,
483495
renamedSegments: renamedSegments,
484496

485497
removeRundown: false,
@@ -520,6 +532,7 @@ async function applyCalculatedIngestChangesToModel(
520532
return {
521533
changedSegmentIds: Array.from(changedSegmentIdsSet),
522534
removedSegmentIds: orphanedSegmentIds, // Only inform about the ones that werent renamed
535+
forceSyncIngestUpdateToPartInstance: computedIngestChanges.forceSyncIngestUpdateToPartInstance,
523536
renamedSegments: renamedSegments,
524537

525538
removeRundown: false,

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export interface PartInstanceToSync {
5858
export async function syncChangesToPartInstances(
5959
context: JobContext,
6060
playoutModel: PlayoutModel,
61-
ingestModel: IngestModelReadonly
61+
ingestModel: IngestModelReadonly,
62+
forceSyncIngestUpdateToPartInstance = false
6263
): Promise<void> {
6364
if (!playoutModel.playlist.activationId) return
6465

@@ -76,7 +77,13 @@ export async function syncChangesToPartInstances(
7677
return
7778
}
7879

79-
const instancesToSync = findInstancesToSync(context, playoutModel, ingestModel, playoutRundownModel)
80+
const instancesToSync = findInstancesToSync(
81+
context,
82+
playoutModel,
83+
ingestModel,
84+
playoutRundownModel,
85+
forceSyncIngestUpdateToPartInstance
86+
)
8087

8188
const worker = new SyncChangesToPartInstancesWorker(context, playoutModel, ingestModel, showStyle, blueprint)
8289

@@ -299,7 +306,8 @@ export function findInstancesToSync(
299306
context: JobContext,
300307
playoutModel: PlayoutModel,
301308
ingestModel: IngestModelReadonly,
302-
playoutRundownModel: PlayoutRundownModel
309+
playoutRundownModel: PlayoutRundownModel,
310+
_forceSyncIngestUpdateToPartInstance = false
303311
): PartInstanceToSync[] {
304312
const currentPartInstance = playoutModel.currentPartInstance
305313
const nextPartInstance = playoutModel.nextPartInstance

0 commit comments

Comments
 (0)