@@ -75,16 +75,9 @@ export async function syncChangesToPartInstances(
7575 return
7676 }
7777
78- const worker = new SyncChangesToPartInstancesWorker (
79- context ,
80- playoutModel ,
81- ingestModel ,
82- playoutRundownModel ,
83- showStyle ,
84- blueprint
85- )
78+ const instancesToSync = findInstancesToSync ( context , playoutModel , ingestModel , playoutRundownModel )
8679
87- const instancesToSync = worker . findInstancesToSync ( )
80+ const worker = new SyncChangesToPartInstancesWorker ( context , playoutModel , ingestModel , showStyle , blueprint )
8881
8982 for ( const instanceToSync of instancesToSync ) {
9083 await worker . syncChangesToPartInstance ( instanceToSync )
@@ -100,102 +93,23 @@ export class SyncChangesToPartInstancesWorker {
10093 readonly #context: JobContext
10194 readonly #playoutModel: PlayoutModel
10295 readonly #ingestModel: IngestModelReadonly
103- readonly #playoutRundownModel: PlayoutRundownModel
10496 readonly #showStyle: ReadonlyDeep < ProcessedShowStyleCompound >
10597 readonly #blueprint: ReadonlyDeep < WrappedShowStyleBlueprint >
10698
10799 constructor (
108100 context : JobContext ,
109101 playoutModel : PlayoutModel ,
110102 ingestModel : IngestModelReadonly ,
111- playoutRundownModel : PlayoutRundownModel ,
112103 showStyle : ReadonlyDeep < ProcessedShowStyleCompound > ,
113104 blueprint : ReadonlyDeep < WrappedShowStyleBlueprint >
114105 ) {
115106 this . #context = context
116107 this . #playoutModel = playoutModel
117108 this . #ingestModel = ingestModel
118- this . #playoutRundownModel = playoutRundownModel
119109 this . #showStyle = showStyle
120110 this . #blueprint = blueprint
121111 }
122112
123- findInstancesToSync ( ) : PartInstanceToSync [ ] {
124- const currentPartInstance = this . #playoutModel. currentPartInstance
125- const nextPartInstance = this . #playoutModel. nextPartInstance
126- const previousPartInstance = this . #playoutModel. previousPartInstance
127-
128- const instancesToSync : PartInstanceToSync [ ] = [ ]
129- if ( currentPartInstance ) {
130- // If the currentPartInstance is adlibbed we probably also need to find the earliest
131- // non-adlibbed Part within this segment and check it for updates too. It may have something
132- // changed (like timing) that will affect what's going on.
133- // The previous "planned" Part Instance needs to be inserted into the `instances` first, so that
134- // it's ran first through the blueprints.
135- if ( currentPartInstance . partInstance . orphaned === 'adlib-part' ) {
136- const partAndPartInstance = findLastUnorphanedPartInstanceInSegment (
137- this . #playoutModel,
138- currentPartInstance . partInstance
139- )
140- if ( partAndPartInstance ) {
141- const lastPartRundownModel = findPlayoutRundownModel (
142- this . #playoutRundownModel,
143- this . #playoutModel,
144- partAndPartInstance . partInstance . partInstance . part . rundownId
145- )
146-
147- insertToSyncedInstanceCandidates (
148- this . #context,
149- instancesToSync ,
150- this . #playoutModel,
151- lastPartRundownModel ,
152- this . #ingestModel,
153- partAndPartInstance . partInstance ,
154- null ,
155- partAndPartInstance . part ,
156- 'previous'
157- )
158- }
159- }
160-
161- // We can now run the current Part Instance.
162- const currentPartRundownModel = findPlayoutRundownModel (
163- this . #playoutRundownModel,
164- this . #playoutModel,
165- currentPartInstance . partInstance . part . rundownId
166- )
167- findPartAndInsertToSyncedInstanceCandidates (
168- this . #context,
169- instancesToSync ,
170- this . #playoutModel,
171- currentPartRundownModel ,
172- this . #ingestModel,
173- currentPartInstance ,
174- previousPartInstance ,
175- 'current'
176- )
177- }
178- if ( nextPartInstance ) {
179- const nextPartRundownModel = findPlayoutRundownModel (
180- this . #playoutRundownModel,
181- this . #playoutModel,
182- nextPartInstance . partInstance . part . rundownId
183- )
184- findPartAndInsertToSyncedInstanceCandidates (
185- this . #context,
186- instancesToSync ,
187- this . #playoutModel,
188- nextPartRundownModel ,
189- this . #ingestModel,
190- nextPartInstance ,
191- currentPartInstance ,
192- currentPartInstance ?. isTooCloseToAutonext ( false ) ? 'current' : 'next'
193- )
194- }
195-
196- return instancesToSync
197- }
198-
199113 async syncChangesToPartInstance ( instanceToSync : PartInstanceToSync ) : Promise < void > {
200114 const { existingPartInstance } = instanceToSync
201115
@@ -222,7 +136,7 @@ export class SyncChangesToPartInstancesWorker {
222136 } ,
223137 this . #context. studio ,
224138 this . #showStyle,
225- this . # playoutRundownModel. rundown ,
139+ instanceToSync . playoutRundownModel . rundown ,
226140 existingPartInstance ,
227141 proposedPieceInstances ,
228142 instanceToSync . playStatus
@@ -341,6 +255,87 @@ export class SyncChangesToPartInstancesWorker {
341255 }
342256}
343257
258+ export function findInstancesToSync (
259+ context : JobContext ,
260+ playoutModel : PlayoutModel ,
261+ ingestModel : IngestModelReadonly ,
262+ playoutRundownModel : PlayoutRundownModel
263+ ) : PartInstanceToSync [ ] {
264+ const currentPartInstance = playoutModel . currentPartInstance
265+ const nextPartInstance = playoutModel . nextPartInstance
266+ const previousPartInstance = playoutModel . previousPartInstance
267+
268+ const instancesToSync : PartInstanceToSync [ ] = [ ]
269+ 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 ,
290+ playoutModel ,
291+ lastPartRundownModel ,
292+ ingestModel ,
293+ partAndPartInstance . partInstance ,
294+ null ,
295+ partAndPartInstance . part ,
296+ 'previous'
297+ )
298+ }
299+ }
300+
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+ )
317+ }
318+ 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+ )
334+ }
335+
336+ return instancesToSync
337+ }
338+
344339/**
345340 * Inserts given PartInstances and underlying Part to the list of PartInstances to be synced
346341 */
0 commit comments