Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Sep 5, 2024
1 parent cd59f9a commit bf42a57
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 126 deletions.
137 changes: 26 additions & 111 deletions packages/corelib/src/dataModel/ExpectedPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {
AdLibActionId,
BucketAdLibActionId,
BucketAdLibId,
BucketId,
ExpectedPackageId,
PartId,
PartInstanceId,
PieceId,
PieceInstanceId,
RundownBaselineAdLibActionId,
Expand All @@ -27,20 +25,13 @@ import { ReadonlyDeep } from 'type-fest'
The Package Manager will then copy the file to the right place.
*/

export type ExpectedPackageFromRundown = ExpectedPackageDBFromPiece | ExpectedPackageDBFromAdLibAction

export type ExpectedPackageFromRundownBaseline =
| ExpectedPackageDBFromBaselineAdLibAction
| ExpectedPackageDBFromBaselineAdLibPiece
| ExpectedPackageDBFromRundownBaselineObjects

export type ExpectedPackageDBFromBucket = ExpectedPackageDBFromBucketAdLib | ExpectedPackageDBFromBucketAdLibAction

export type ExpectedPackageDB =
| ExpectedPackageFromRundown
| ExpectedPackageDBFromBucket
| ExpectedPackageFromRundownBaseline
| ExpectedPackageDBFromStudioBaselineObjects
// export type ExpectedPackageDB =
// | ExpectedPackageFromRundown
// | ExpectedPackageDBFromBucket
// | ExpectedPackageFromRundownBaseline
// | ExpectedPackageDBFromStudioBaselineObjects

export enum ExpectedPackageDBType {
PIECE = 'piece',
Expand All @@ -54,22 +45,6 @@ export enum ExpectedPackageDBType {
STUDIO_BASELINE_OBJECTS = 'studio_baseline_objects',
PIECE_INSTANCE = 'piece_instance',
}
export interface ExpectedPackageDBBaseSimple {
_id: ExpectedPackageId

package: ReadonlyDeep<ExpectedPackage.Any>

/** The local package id - as given by the blueprints */
blueprintPackageId: string // TODO - remove this?

/** The studio of the Rundown of the Piece this package belongs to */
studioId: StudioId

/** Hash that changes whenever the content or version changes. See getContentVersionHash() */
contentVersionHash: string

created: Time
}

/*
* What about this new concept. The aim here is to avoid the constant inserting and deleting of expectedPackages during playout, and avoiding duplicate packages with the same content.
Expand Down Expand Up @@ -152,80 +127,27 @@ export type ExpectedPackageIngestSourceRundownBaseline =

export type ExpectedPackageIngestSource = ExpectedPackageIngestSourcePart | ExpectedPackageIngestSourceRundownBaseline

export interface ExpectedPackageWithId {
_id: ExpectedPackageId
expectedPackage: ReadonlyDeep<ExpectedPackage.Any>
}

export interface ExpectedPackageDBBase extends ExpectedPackageDBBaseSimple {
fromPieceType: ExpectedPackageDBType
}
export interface ExpectedPackageDBFromPiece extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.PIECE | ExpectedPackageDBType.ADLIB_PIECE
/** The Piece this package belongs to */
pieceId: PieceId
/** The Part this package belongs to */
partId: PartId
/** The Segment this package belongs to */
segmentId: SegmentId
/** The rundown of the Piece this package belongs to */
rundownId: RundownId
}

export interface ExpectedPackageDBFromBaselineAdLibPiece extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.BASELINE_ADLIB_PIECE
/** The Piece this package belongs to */
pieceId: PieceId
/** The rundown of the Piece this package belongs to */
rundownId: RundownId
}

export interface ExpectedPackageDBFromAdLibAction extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.ADLIB_ACTION
/** The Adlib Action this package belongs to */
pieceId: AdLibActionId
/** The Part this package belongs to */
partId: PartId
/** The Segment this package belongs to */
segmentId: SegmentId
/** The rundown of the Piece this package belongs to */
rundownId: RundownId
}
export interface ExpectedPackageDBFromBaselineAdLibAction extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.BASELINE_ADLIB_ACTION
/** The Piece this package belongs to */
pieceId: RundownBaselineAdLibActionId
/** The rundown of the Piece this package belongs to */
rundownId: RundownId
}

export interface ExpectedPackageDBFromRundownBaselineObjects extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.RUNDOWN_BASELINE_OBJECTS
/** The rundown of the Piece this package belongs to */
rundownId: RundownId
pieceId: null
}
export interface ExpectedPackageDBFromStudioBaselineObjects extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.STUDIO_BASELINE_OBJECTS
pieceId: null
}

export interface ExpectedPackageDBFromBucketAdLib extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB
bucketId: BucketId
/** The Bucket adlib this package belongs to */
pieceId: BucketAdLibId
/** The `externalId` of the Bucket adlib this package belongs to */
pieceExternalId: string
}
export interface ExpectedPackageDBFromBucketAdLibAction extends ExpectedPackageDBBase {
fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB_ACTION
bucketId: BucketId
/** The Bucket adlib-action this package belongs to */
pieceId: BucketAdLibActionId
/** The `externalId` of the Bucket adlib-action this package belongs to */
pieceExternalId: string
}
// export interface ExpectedPackageDBFromStudioBaselineObjects extends ExpectedPackageDBBase {
// fromPieceType: ExpectedPackageDBType.STUDIO_BASELINE_OBJECTS
// pieceId: null
// }

// export interface ExpectedPackageDBFromBucketAdLib extends ExpectedPackageDBBase {
// fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB
// bucketId: BucketId
// /** The Bucket adlib this package belongs to */
// pieceId: BucketAdLibId
// /** The `externalId` of the Bucket adlib this package belongs to */
// pieceExternalId: string
// }
// export interface ExpectedPackageDBFromBucketAdLibAction extends ExpectedPackageDBBase {
// fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB_ACTION
// bucketId: BucketId
// /** The Bucket adlib-action this package belongs to */
// pieceId: BucketAdLibActionId
// /** The `externalId` of the Bucket adlib-action this package belongs to */
// pieceExternalId: string
// }

export function getContentVersionHash(expectedPackage: ReadonlyDeep<Omit<ExpectedPackage.Any, '_id'>>): string {
return hashObj({
Expand Down Expand Up @@ -266,10 +188,3 @@ export function getExpectedPackageIdNew(

return protectString(`${rundownId}_${getHash(objHash)}`)
}

export function unwrapExpectedPackages(
expectedPackages: ReadonlyDeep<ExpectedPackageDBBase[]> | undefined
): ReadonlyDeep<ExpectedPackage.Any[]> {
if (!expectedPackages) return []
return expectedPackages.map((p) => p.package)
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class SyncIngestUpdateToPartInstanceContext
: null

if (postProcessed) {
this.expectedPackages.ensurePackagesExistMap(
this.expectedPackages.createPackagesIfMissingFromMap(
this.partInstance.partInstance.rundownId,
postProcessed.expectedPackages
)
Expand Down Expand Up @@ -131,7 +131,7 @@ export class SyncIngestUpdateToPartInstanceContext
)
const piece = processedPieces.docs[0]

this.expectedPackages.ensurePackagesExistMap(
this.expectedPackages.createPackagesIfMissingFromMap(
this.partInstance.partInstance.rundownId,
processedPieces.expectedPackages
)
Expand Down Expand Up @@ -183,7 +183,7 @@ export class SyncIngestUpdateToPartInstanceContext
})
}
if (trimmedPiece.expectedPackages) {
this.expectedPackages.ensurePackagesExist(
this.expectedPackages.createPackagesIfMissing(
pieceInstance.pieceInstance.rundownId,
trimmedPiece.expectedPackages
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class PartAndPieceInstanceActionService {
const piece = postProcessed.docs[0]
piece._id = getRandomId() // Make id random, as postProcessPieces is too predictable (for ingest)

this._playoutModel.expectedPackages.ensurePackagesExistMap(
this._playoutModel.expectedPackages.createPackagesIfMissingFromMap(
this._rundown.rundown._id,
postProcessed.expectedPackages
)
Expand Down Expand Up @@ -358,7 +358,7 @@ export class PartAndPieceInstanceActionService {

if (trimmedPiece.expectedPackages) {
// nocommit - this needs to go through some postProcess
this._playoutModel.expectedPackages.ensurePackagesExist(
this._playoutModel.expectedPackages.createPackagesIfMissing(
pieceInstance.pieceInstance.rundownId,
trimmedPiece.expectedPackages
)
Expand Down Expand Up @@ -452,7 +452,10 @@ export class PartAndPieceInstanceActionService {
throw new Error('Cannot queue a part which is not playable')
}

this._playoutModel.expectedPackages.ensurePackagesExistMap(this._rundown.rundown._id, pieces.expectedPackages)
this._playoutModel.expectedPackages.createPackagesIfMissingFromMap(
this._rundown.rundown._id,
pieces.expectedPackages
)

// Do the work
const newPartInstance = await insertQueuedPartWithPieces(
Expand Down
2 changes: 1 addition & 1 deletion packages/job-worker/src/playout/adlibJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async function pieceTakeNowAsAdlib(
| { partInstance: PlayoutPartInstanceModel; pieceInstance: PlayoutPieceInstanceModel }
| undefined
): Promise<void> {
playoutModel.expectedPackages.ensurePackagesExist(currentPartInstance.partInstance.rundownId, expectedPackages) // nocommit - what if the genericAdlibPiece doesn't quite match the set of packages?
playoutModel.expectedPackages.createPackagesIfMissing(currentPartInstance.partInstance.rundownId, expectedPackages) // nocommit - what if the genericAdlibPiece doesn't quite match the set of packages?

const genericAdlibPiece = convertAdLibToGenericPiece(pieceToCopy, false)
/*const newPieceInstance = */ currentPartInstance.insertAdlibbedPiece(genericAdlibPiece, pieceToCopy._id)
Expand Down
10 changes: 8 additions & 2 deletions packages/job-worker/src/playout/adlibUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export async function innerStartOrQueueAdLibPiece(
expectedDurationWithTransition: adLibPiece.expectedDuration, // Filled in later
}

playoutModel.expectedPackages.ensurePackagesExist(currentPartInstance.partInstance.rundownId, expectedPackages) // nocommit - what if the genericAdlibPiece doesn't quite match the set of packages?
playoutModel.expectedPackages.createPackagesIfMissing(
currentPartInstance.partInstance.rundownId,
expectedPackages
) // nocommit - what if the genericAdlibPiece doesn't quite match the set of packages?

const genericAdlibPiece = convertAdLibToGenericPiece(adLibPiece, true)
const newPartInstance = await insertQueuedPartWithPieces(
Expand All @@ -65,7 +68,10 @@ export async function innerStartOrQueueAdLibPiece(

// syncPlayheadInfinitesForNextPartInstance is handled by setNextPart
} else {
playoutModel.expectedPackages.ensurePackagesExist(currentPartInstance.partInstance.rundownId, expectedPackages) // nocommit - what if the adLibPiece doesn't quite match the set of packages?
playoutModel.expectedPackages.createPackagesIfMissing(
currentPartInstance.partInstance.rundownId,
expectedPackages
) // nocommit - what if the adLibPiece doesn't quite match the set of packages?

const genericAdlibPiece = convertAdLibToGenericPiece(adLibPiece, false)
currentPartInstance.insertAdlibbedPiece(genericAdlibPiece, adLibPiece._id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export interface PlayoutExpectedPackagesModel extends PlayoutExpectedPackagesMod

ensurePackagesAreLoaded(expectedPackages: PieceExpectedPackage[]): Promise<ExpectedPackage.Any[]>

ensurePackagesExist(rundownId: RundownId, expectedPackages: ReadonlyDeep<ExpectedPackage.Any[]>): void
createPackagesIfMissing(rundownId: RundownId, expectedPackages: ReadonlyDeep<ExpectedPackage.Any[]>): void

ensurePackagesExistMap(
createPackagesIfMissingFromMap(
rundownId: RundownId,
expectedPackages: ReadonlyMap<ExpectedPackageId, ReadonlyDeep<ExpectedPackage.Any>>
): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { PlayoutModel, PlayoutModelPreInit } from '../PlayoutModel'
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
import { RundownBaselineObj } from '@sofie-automation/corelib/dist/dataModel/RundownBaselineObj'
import { PlayoutExpectedPackagesModelImpl } from './PlayoutExpectedPackagesModelImpl'
import { ExpectedPackageDBNew } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'

/**
* Load a PlayoutModelPreInit for the given RundownPlaylist
Expand Down Expand Up @@ -91,12 +92,15 @@ export async function createPlayoutModelFromIngestModel(
const expectedPackages = new PlayoutExpectedPackagesModelImpl()
// nocommit - populate some content from the ingestModel

const [partInstances, rundownsWithContent, timeline] = await Promise.all([
const [partInstances, rundownsWithContent, timeline, expectedPackagesDocs] = await Promise.all([
loadPartInstances(context, expectedPackages, loadedPlaylist, rundownIds),
loadRundowns(context, ingestModel, rundowns),
loadTimeline(context),
loadExpectedPackages(context),
])

expectedPackages.populateWithPackages(expectedPackagesDocs)

const res = new PlayoutModelImpl(
context,
playlistLock,
Expand Down Expand Up @@ -157,12 +161,15 @@ export async function createPlayoutModelfromInitModel(

const expectedPackages = new PlayoutExpectedPackagesModelImpl()

const [partInstances, rundownsWithContent, timeline] = await Promise.all([
const [partInstances, rundownsWithContent, timeline, expectedPackagesDocs] = await Promise.all([
loadPartInstances(context, expectedPackages, initModel.playlist, rundownIds),
loadRundowns(context, null, initModel.rundowns),
loadTimeline(context),
loadExpectedPackages(context),
])

expectedPackages.populateWithPackages(expectedPackagesDocs)

const res = new PlayoutModelImpl(
context,
initModel.playlistLock,
Expand Down Expand Up @@ -334,3 +341,8 @@ async function loadPartInstances(

return allPartInstances
}

async function loadExpectedPackages(context: JobContext): Promise<ExpectedPackageDBNew[]> {
// nocommit: load the expectedPackages from the database
return []
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export class PlayoutExpectedPackagesModelImpl implements PlayoutExpectedPackages
throw new Error('Method not implemented.')
}

ensurePackagesExist(_rundownId: RundownId, _expectedPackages: ReadonlyDeep<ExpectedPackage.Any[]>): void {
createPackagesIfMissing(_rundownId: RundownId, _expectedPackages: ReadonlyDeep<ExpectedPackage.Any[]>): void {
throw new Error('Method not implemented.')
}

ensurePackagesExistMap(
createPackagesIfMissingFromMap(
_rundownId: RundownId,
_expectedPackages: ReadonlyMap<ExpectedPackageId, ReadonlyDeep<ExpectedPackage.Any>>
): void {
Expand All @@ -49,6 +49,8 @@ export class PlayoutExpectedPackagesModelImpl implements PlayoutExpectedPackages
throw new Error('Method not implemented.')
}

populateWithPackages(packages: ExpectedPackageDBNew[]): void {}

async saveAllToDatabase(): Promise<void> {
throw new Error('Method not implemented.')
}
Expand Down

0 comments on commit bf42a57

Please sign in to comment.