From 4c9834a24ea2b8514f429a74c888692e097017e9 Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Fri, 13 Oct 2023 16:21:36 +0100 Subject: [PATCH] feat: support packageinfo update flow for buckets and studio baseline --- meteor/server/api/__tests__/cleanup.test.ts | 2 + meteor/server/api/buckets.ts | 5 +- meteor/server/api/ingest/packageInfo.ts | 151 ++++++++---------- .../src/dataModel/BucketAdLibAction.ts | 2 + .../corelib/src/dataModel/BucketAdLibPiece.ts | 8 +- packages/corelib/src/worker/ingest.ts | 14 +- .../job-worker/src/blueprints/postProcess.ts | 20 ++- .../job-worker/src/ingest/bucket/import.ts | 112 ++++++++++--- .../job-worker/src/ingest/expectedPackages.ts | 1 + packages/job-worker/src/ingest/packageInfo.ts | 15 -- .../job-worker/src/workers/ingest/jobs.ts | 10 +- 11 files changed, 195 insertions(+), 145 deletions(-) diff --git a/meteor/server/api/__tests__/cleanup.test.ts b/meteor/server/api/__tests__/cleanup.test.ts index 391babd8f95..b9f2f34ec45 100644 --- a/meteor/server/api/__tests__/cleanup.test.ts +++ b/meteor/server/api/__tests__/cleanup.test.ts @@ -221,6 +221,7 @@ async function setDefaultDatatoDB(env: DefaultEnvironment, now: number) { actionId: '', display: {} as any, importVersions: {} as any, + ingestInfo: undefined, showStyleVariantId, userData: {} as any, userDataManifest: {} as any, @@ -232,6 +233,7 @@ async function setDefaultDatatoDB(env: DefaultEnvironment, now: number) { studioId, showStyleBaseId: env.showStyleBaseId, importVersions: {} as any, + ingestInfo: undefined, showStyleVariantId, _rank: 0, content: {} as any, diff --git a/meteor/server/api/buckets.ts b/meteor/server/api/buckets.ts index 3c327aeed08..7d2c75a9c26 100644 --- a/meteor/server/api/buckets.ts +++ b/meteor/server/api/buckets.ts @@ -1,7 +1,7 @@ import * as _ from 'underscore' import { Meteor } from 'meteor/meteor' import { Bucket } from '../../lib/collections/Buckets' -import { getRandomId, literal } from '../../lib/lib' +import { getRandomId, getRandomString, literal } from '../../lib/lib' import { BucketSecurity } from '../security/buckets' import { BucketAdLib } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibPiece' import { AdLibAction, AdLibActionCommon } from '@sofie-automation/corelib/dist/dataModel/AdlibAction' @@ -165,12 +165,13 @@ export namespace BucketsAPI { adLibAction = { ...(_.omit(action, ['partId', 'rundownId']) as Omit), _id: getRandomId(), - externalId: '', // TODO - is this ok? + externalId: getRandomString(), // This needs to be something unique, so that the regenerate logic doesn't get it mixed up with something else bucketId: access.bucket._id, studioId: access.studioId, showStyleBaseId: rundown.showStyleBaseId, showStyleVariantId: action.allVariants ? null : rundown.showStyleVariantId, importVersions: rundown.importVersions, + ingestInfo: undefined, } } diff --git a/meteor/server/api/ingest/packageInfo.ts b/meteor/server/api/ingest/packageInfo.ts index 34a212c1b61..2fb781ba6ba 100644 --- a/meteor/server/api/ingest/packageInfo.ts +++ b/meteor/server/api/ingest/packageInfo.ts @@ -1,19 +1,21 @@ -import { ExpectedPackageDBType } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages' +import { + ExpectedPackageDBFromBucketAdLib, + ExpectedPackageDBFromBucketAdLibAction, + ExpectedPackageDBFromStudioBaselineObjects, + ExpectedPackageDBType, +} from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages' import { PackageInfoDB } from '@sofie-automation/corelib/dist/dataModel/PackageInfos' -import { Buckets, ExpectedPackages, Rundowns } from '../../collections' +import { BucketAdLibActions, BucketAdLibs, ExpectedPackages, Rundowns } from '../../collections' import { assertNever, lazyIgnore } from '../../../lib/lib' import { logger } from '../../logging' import { runIngestOperation } from './lib' import { IngestJobs } from '@sofie-automation/corelib/dist/worker/ingest' -import { - BucketAdLibActionId, - BucketAdLibId, - BucketId, - ExpectedPackageId, - RundownId, -} from '@sofie-automation/corelib/dist/dataModel/Ids' -import { Bucket } from '../../../lib/collections/Buckets' +import { ExpectedPackageId, RundownId } from '@sofie-automation/corelib/dist/dataModel/Ids' import { Rundown } from '@sofie-automation/corelib/dist/dataModel/Rundown' +import { BucketAdLibAction } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibAction' +import { BucketAdLib } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibPiece' +import { QueueStudioJob } from '../../worker/worker' +import { StudioJobs } from '@sofie-automation/corelib/dist/worker/studio' export async function onUpdatedPackageInfo(packageId: ExpectedPackageId, _doc: PackageInfoDB | null): Promise { logger.info(`PackageInfo updated "${packageId}"`) @@ -56,40 +58,40 @@ export async function onUpdatedPackageInfo(packageId: ExpectedPackageId, _doc: P ) break } - case ExpectedPackageDBType.BUCKET_ADLIB: + case ExpectedPackageDBType.BUCKET_ADLIB: { + const bucketAction = (await BucketAdLibs.findOneAsync( + { _id: pkg.pieceId, bucketId: pkg.bucketId }, + { + projection: { externalId: 1 }, + } + )) as Pick + + if (bucketAction) { + onUpdatedPackageInfoForBucketItemDebounce(pkg, bucketAction.externalId) + } else { + logger.info(`onUpdatedPackageInfo: Received update for missing BucketAdLib: ${pkg.pieceId}`) + } + + break + } case ExpectedPackageDBType.BUCKET_ADLIB_ACTION: { - const identifier = `${pkg.bucketId}_${pkg.pieceId}` - const existingEntry = pendingBucketItemPackageUpdates.get(identifier) - if (existingEntry) { - // already queued, add to the batch - existingEntry.packageIds.push(pkg._id) + const bucketAction = (await BucketAdLibActions.findOneAsync( + { _id: pkg.pieceId, bucketId: pkg.bucketId }, + { + projection: { externalId: 1 }, + } + )) as Pick + + if (bucketAction) { + onUpdatedPackageInfoForBucketItemDebounce(pkg, bucketAction.externalId) } else { - pendingBucketItemPackageUpdates.set(identifier, { - bucketId: pkg.bucketId, - pieceId: pkg.pieceId, - packageIds: [pkg._id], - }) + logger.info(`onUpdatedPackageInfo: Received update for missing BucketAdLibAction: ${pkg.pieceId}`) } - lazyIgnore( - `onUpdatedPackageInfoForBucket_${identifier}`, - () => { - const updateInfo = pendingBucketItemPackageUpdates.get(identifier) - if (updateInfo) { - pendingBucketItemPackageUpdates.delete(identifier) - onUpdatedPackageInfoForBucketItem(updateInfo).catch((e) => { - logger.error( - `Updating ExpectedPackages for Bucket "${updateInfo.bucketId}" Item "${updateInfo.pieceId}" failed: ${e}` - ) - }) - } - }, - 1000 - ) break } case ExpectedPackageDBType.STUDIO_BASELINE_OBJECTS: - // Ignore, as we can't handle that for now + onUpdatedPackageInfoForStudioBaselineDebounce(pkg) break default: assertNever(pkg) @@ -128,51 +130,38 @@ async function onUpdatedPackageInfoForRundown( }) } -interface PendingBucketItemPackageUpdateInfoBase { - bucketId: BucketId - pieceId: BucketAdLibId | BucketAdLibActionId - packageIds: ExpectedPackageId[] +function onUpdatedPackageInfoForBucketItemDebounce( + pkg: ExpectedPackageDBFromBucketAdLib | ExpectedPackageDBFromBucketAdLibAction, + externalId: string +) { + lazyIgnore( + `onUpdatedPackageInfoForBucket_${pkg.studioId}_${pkg.bucketId}_${externalId}`, + () => { + runIngestOperation(pkg.studioId, IngestJobs.BucketItemRegenerate, { + bucketId: pkg.bucketId, + externalId: externalId, + }).catch((err) => { + logger.error( + `Updating ExpectedPackages for Bucket "${pkg.bucketId}" Item "${externalId}" failed: ${err}` + ) + }) + }, + 1000 + ) } -// interface PendingBucketAdLibPiecePackageUpdateInfo extends PendingBucketItemPackageUpdateInfoBase { -// fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB -// /** The Bucket adlib this package belongs to */ -// pieceId: BucketAdLibId -// } -// interface PendingBucketAdLibActionPackageUpdateInfo extends PendingBucketItemPackageUpdateInfoBase { -// fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB_ACTION -// /** The Bucket adlib-action this package belongs to */ -// pieceId: BucketAdLibActionId -// } - -type SomePendingBucketItemPackageUpdateInfo = PendingBucketItemPackageUpdateInfoBase -// | PendingBucketAdLibPiecePackageUpdateInfo -// | PendingBucketAdLibActionPackageUpdateInfo - -const pendingBucketItemPackageUpdates = new Map() - -async function onUpdatedPackageInfoForBucketItem(info: SomePendingBucketItemPackageUpdateInfo): Promise { - if (info.packageIds.length === 0) { - return - } - - const tmpBucket = (await Buckets.findOneAsync(info.bucketId, { - projection: { - studioId: 1, +function onUpdatedPackageInfoForStudioBaselineDebounce(pkg: ExpectedPackageDBFromStudioBaselineObjects) { + lazyIgnore( + `onUpdatedPackageInfoForStudioBaseline_${pkg.studioId}`, + () => { + QueueStudioJob(StudioJobs.UpdateStudioBaseline, pkg.studioId, undefined) + .then(async (job) => { + await job.complete + }) + .catch((err) => { + logger.error(`Updating ExpectedPackages for StudioBaseline "${pkg.studioId}" failed: ${err}`) + }) }, - })) as Pick | undefined - if (!tmpBucket) { - logger.error( - `onUpdatedPackageInfoForBucketItem: Missing Bucket "${info.bucketId}" for packages "${info.packageIds.join( - ', ' - )}"` - ) - return - } - - await runIngestOperation(tmpBucket.studioId, IngestJobs.PackageInfosUpdatedBucketItem, { - bucketId: info.bucketId, - pieceId: info.pieceId, - packageIds: info.packageIds, - }) + 1000 + ) } diff --git a/packages/corelib/src/dataModel/BucketAdLibAction.ts b/packages/corelib/src/dataModel/BucketAdLibAction.ts index 3190a834675..e1b500c2f76 100644 --- a/packages/corelib/src/dataModel/BucketAdLibAction.ts +++ b/packages/corelib/src/dataModel/BucketAdLibAction.ts @@ -1,6 +1,7 @@ import { BucketAdLibActionId, BucketId, StudioId, ShowStyleVariantId, ShowStyleBaseId } from './Ids' import { RundownImportVersions } from './Rundown' import { AdLibActionCommon } from './AdlibAction' +import { BucketAdLibIngestInfo } from './BucketAdLibPiece' export interface BucketAdLibAction extends Omit { _id: BucketAdLibActionId @@ -18,6 +19,7 @@ export interface BucketAdLibAction extends Omit /** if showStyleVariantId is null, the adlibAction can be used with any variant */ showStyleVariantId: ShowStyleVariantId | null importVersions: RundownImportVersions // TODO - is this good? + ingestInfo: BucketAdLibIngestInfo | undefined /** The following extended interface allows assigning namespace information to the actions as they are stored in the * database after being emitted from the blueprints diff --git a/packages/corelib/src/dataModel/BucketAdLibPiece.ts b/packages/corelib/src/dataModel/BucketAdLibPiece.ts index 146e630121f..25b6e453127 100644 --- a/packages/corelib/src/dataModel/BucketAdLibPiece.ts +++ b/packages/corelib/src/dataModel/BucketAdLibPiece.ts @@ -1,8 +1,13 @@ -import { IBlueprintAdLibPiece, SomeContent } from '@sofie-automation/blueprints-integration' +import { IBlueprintAdLibPiece, IngestAdlib, SomeContent } from '@sofie-automation/blueprints-integration' import { BucketAdLibId, BucketId, StudioId, ShowStyleVariantId, ShowStyleBaseId } from './Ids' import { PieceTimelineObjectsBlob } from './Piece' import { RundownImportVersions } from './Rundown' +export interface BucketAdLibIngestInfo { + limitToShowStyleVariantIds: ShowStyleVariantId[] | undefined + payload: IngestAdlib +} + export interface BucketAdLib extends Omit { _id: BucketAdLibId bucketId: BucketId @@ -20,6 +25,7 @@ export interface BucketAdLib extends Omit { showStyleVariantId: ShowStyleVariantId | null importVersions: RundownImportVersions // TODO - is this good? + ingestInfo: BucketAdLibIngestInfo | undefined /** Stringified timelineObjects */ timelineObjectsString: PieceTimelineObjectsBlob diff --git a/packages/corelib/src/worker/ingest.ts b/packages/corelib/src/worker/ingest.ts index 348c61e1abc..58af8d51f52 100644 --- a/packages/corelib/src/worker/ingest.ts +++ b/packages/corelib/src/worker/ingest.ts @@ -1,7 +1,6 @@ import { AdLibActionId, BucketAdLibActionId, - BucketAdLibId, BucketId, ExpectedPackageId, PeripheralDeviceId, @@ -124,6 +123,7 @@ export enum IngestJobs { // For now these are in this queue, but if this gets split up to be per rundown, then a single bucket queue will be needed BucketItemImport = 'bucketItemImport', + BucketItemRegenerate = 'bucketItemRegenerate', BucketActionRegenerateExpectedPackages = 'bucketActionRegenerateExpectedPackages', BucketActionModify = 'bucketActionModify', BucketPieceModify = 'bucketPieceModify', @@ -219,12 +219,6 @@ export interface PackageInfosUpdatedRundownProps extends IngestPropsBase { packageIds: ExpectedPackageId[] } -export interface PackageInfosUpdatedBucketItemProps { - bucketId: BucketId - pieceId: BucketAdLibId | BucketAdLibActionId - packageIds: ExpectedPackageId[] -} - export interface UserRundownPropsBase { rundownId: RundownId } @@ -239,6 +233,10 @@ export interface BucketItemImportProps { showStyleVariantIds?: ShowStyleVariantId[] payload: IngestAdlib } +export interface BucketItemRegenerateProps { + bucketId: BucketId + externalId: string +} export interface BucketActionRegenerateExpectedPackagesProps { actionId: BucketAdLibActionId } @@ -290,12 +288,12 @@ export type IngestJobFunc = { [IngestJobs.ExpectedPackagesRegenerate]: (data: ExpectedPackagesRegenerateProps) => void [IngestJobs.PackageInfosUpdatedRundown]: (data: PackageInfosUpdatedRundownProps) => void - [IngestJobs.PackageInfosUpdatedBucketItem]: (data: PackageInfosUpdatedBucketItemProps) => void [IngestJobs.UserRemoveRundown]: (data: UserRemoveRundownProps) => void [IngestJobs.UserUnsyncRundown]: (data: UserUnsyncRundownProps) => void [IngestJobs.BucketItemImport]: (data: BucketItemImportProps) => void + [IngestJobs.BucketItemRegenerate]: (data: BucketItemRegenerateProps) => void [IngestJobs.BucketActionModify]: (data: BucketActionModifyProps) => void [IngestJobs.BucketPieceModify]: (data: BucketPieceModifyProps) => void [IngestJobs.BucketActionRegenerateExpectedPackages]: (data: BucketActionRegenerateExpectedPackagesProps) => void diff --git a/packages/job-worker/src/blueprints/postProcess.ts b/packages/job-worker/src/blueprints/postProcess.ts index 9ee2556a36b..6e9d2f8fcaa 100644 --- a/packages/job-worker/src/blueprints/postProcess.ts +++ b/packages/job-worker/src/blueprints/postProcess.ts @@ -35,7 +35,7 @@ import { RundownBaselineAdLibAction } from '@sofie-automation/corelib/dist/dataM import { ArrayElement, getHash, literal, omit } from '@sofie-automation/corelib/dist/lib' import { BucketAdLibAction } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibAction' import { RundownImportVersions } from '@sofie-automation/corelib/dist/dataModel/Rundown' -import { BucketAdLib } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibPiece' +import { BucketAdLib, BucketAdLibIngestInfo } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibPiece' import { interpollateTranslation, wrapTranslatableMessageFromBlueprints, @@ -393,25 +393,28 @@ export function postProcessBucketAdLib( context: JobContext, showStyleCompound: ReadonlyDeep, itemOrig: IBlueprintAdLibPiece, - externalId: string, + ingestInfo: BucketAdLibIngestInfo, blueprintId: BlueprintId, bucketId: BucketId, rank: number | undefined, importVersions: RundownImportVersions ): BucketAdLib { const id: PieceId = protectString( - getHash(`${showStyleCompound.showStyleVariantId}_${context.studioId}_${bucketId}_bucket_adlib_${externalId}`) + getHash( + `${showStyleCompound.showStyleVariantId}_${context.studioId}_${bucketId}_bucket_adlib_${ingestInfo.payload.externalId}` + ) ) const piece: BucketAdLib = { ...itemOrig, content: omit(itemOrig.content, 'timelineObjects'), _id: id, - externalId, + externalId: ingestInfo.payload.externalId, studioId: context.studioId, showStyleBaseId: showStyleCompound._id, showStyleVariantId: showStyleCompound.showStyleVariantId, bucketId, importVersions, + ingestInfo, _rank: rank || itemOrig._rank, timelineObjectsString: EmptyPieceTimelineObjectsBlob, } @@ -439,24 +442,27 @@ export function postProcessBucketAction( context: JobContext, showStyleCompound: ReadonlyDeep, itemOrig: IBlueprintActionManifest, - externalId: string, + ingestInfo: BucketAdLibIngestInfo, blueprintId: BlueprintId, bucketId: BucketId, rank: number | undefined, importVersions: RundownImportVersions ): BucketAdLibAction { const id: AdLibActionId = protectString( - getHash(`${showStyleCompound.showStyleVariantId}_${context.studioId}_${bucketId}_bucket_adlib_${externalId}`) + getHash( + `${showStyleCompound.showStyleVariantId}_${context.studioId}_${bucketId}_bucket_adlib_${ingestInfo.payload.externalId}` + ) ) const action: BucketAdLibAction = { ...omit(itemOrig, 'partId'), _id: id, - externalId, + externalId: ingestInfo.payload.externalId, studioId: context.studioId, showStyleBaseId: showStyleCompound._id, showStyleVariantId: itemOrig.allVariants ? null : showStyleCompound.showStyleVariantId, bucketId, importVersions, + ingestInfo, ...processAdLibActionITranslatableMessages(itemOrig, blueprintId, rank), } diff --git a/packages/job-worker/src/ingest/bucket/import.ts b/packages/job-worker/src/ingest/bucket/import.ts index e7fc0e1284f..d79fac6c4b3 100644 --- a/packages/job-worker/src/ingest/bucket/import.ts +++ b/packages/job-worker/src/ingest/bucket/import.ts @@ -4,7 +4,7 @@ import { IBlueprintActionManifest, IBlueprintAdLibPiece, IngestAdlib } from '@so import { WatchedPackagesHelper } from '../../blueprints/context/watchedPackages' import { JobContext, ProcessedShowStyleCompound } from '../../jobs' import { getSystemVersion } from '../../lib' -import { BucketItemImportProps } from '@sofie-automation/corelib/dist/worker/ingest' +import { BucketItemImportProps, BucketItemRegenerateProps } from '@sofie-automation/corelib/dist/worker/ingest' import { cleanUpExpectedPackagesForBucketAdLibs, cleanUpExpectedPackagesForBucketAdLibsActions, @@ -19,47 +19,111 @@ import { } from '../expectedMediaItems' import { postProcessBucketAction, postProcessBucketAdLib } from '../../blueprints/postProcess' import { stringifyError } from '@sofie-automation/shared-lib/dist/lib/stringifyError' -import { BucketAdLib } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibPiece' +import { BucketAdLib, BucketAdLibIngestInfo } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibPiece' import { BucketAdLibAction } from '@sofie-automation/corelib/dist/dataModel/BucketAdLibAction' import { logger } from '../../logging' import { createShowStyleCompound } from '../../showStyles' import { isAdlibAction } from './util' import { WrappedShowStyleBlueprint } from '../../blueprints/cache' import { ReadonlyDeep } from 'type-fest' -import { BucketId } from '@sofie-automation/corelib/dist/dataModel/Ids' +import { BucketId, ShowStyleBaseId } from '@sofie-automation/corelib/dist/dataModel/Ids' export async function handleBucketItemImport(context: JobContext, data: BucketItemImportProps): Promise { + await regenerateBucketItemFromIngestInfo(context, data.bucketId, data.showStyleBaseId, { + limitToShowStyleVariantIds: data.showStyleVariantIds, + payload: data.payload, + }) +} + +export async function handleBucketItemRegenerate(context: JobContext, data: BucketItemRegenerateProps): Promise { + // These queries could match more than one document, but as they have the same `externalId` they all get regenerated together + const [adlibPiece, adlibAction] = await Promise.all([ + context.directCollections.BucketAdLibPieces.findOne( + { + externalId: data.externalId, + studioId: context.studio._id, + bucketId: data.bucketId, + }, + { + projection: { + showStyleBaseId: 1, + ingestInfo: 1, + }, + } + ) as Promise> | undefined, + context.directCollections.BucketAdLibActions.findOne( + { + externalId: data.externalId, + studioId: context.studio._id, + bucketId: data.bucketId, + }, + { + projection: { + showStyleBaseId: 1, + ingestInfo: 1, + }, + } + ) as Promise> | undefined, + ]) + + // TODO - UserErrors? + if (adlibAction) { + if (!adlibAction.ingestInfo) throw new Error(`Bucket AdLibAction cannot be resynced, it has no ingest data`) + await regenerateBucketItemFromIngestInfo( + context, + data.bucketId, + adlibAction.showStyleBaseId, + adlibAction.ingestInfo + ) + } else if (adlibPiece) { + if (!adlibPiece.ingestInfo) throw new Error(`Bucket AdLibPiece cannot be resynced, it has no ingest data`) + await regenerateBucketItemFromIngestInfo( + context, + data.bucketId, + adlibPiece.showStyleBaseId, + adlibPiece.ingestInfo + ) + } else { + throw new Error(`No Bucket Items with externalId "${data.externalId}" were found`) + } +} + +async function regenerateBucketItemFromIngestInfo( + context: JobContext, + bucketId: BucketId, + showStyleBaseId: ShowStyleBaseId, + ingestInfo: BucketAdLibIngestInfo +): Promise { const [showStyleBase, allShowStyleVariants, allOldAdLibPieces, allOldAdLibActions, blueprint] = await Promise.all([ - context.getShowStyleBase(data.showStyleBaseId), - context.getShowStyleVariants(data.showStyleBaseId), + context.getShowStyleBase(showStyleBaseId), + context.getShowStyleVariants(showStyleBaseId), context.directCollections.BucketAdLibPieces.findFetch( { - externalId: data.payload.externalId, - showStyleBaseId: data.showStyleBaseId, + externalId: ingestInfo.payload.externalId, + showStyleBaseId: showStyleBaseId, studioId: context.studio._id, - bucketId: data.bucketId, + bucketId: bucketId, }, { projection: { _id: 1 } } ) as Promise[]>, context.directCollections.BucketAdLibActions.findFetch( { - externalId: data.payload.externalId, - showStyleBaseId: data.showStyleBaseId, + externalId: ingestInfo.payload.externalId, + showStyleBaseId: showStyleBaseId, studioId: context.studio._id, - bucketId: data.bucketId, + bucketId: bucketId, }, { projection: { _id: 1 } } ) as Promise[]>, - context.getShowStyleBlueprint(data.showStyleBaseId), + context.getShowStyleBlueprint(showStyleBaseId), ]) - if (!showStyleBase) throw new Error(`ShowStyleBase "${data.showStyleBaseId}" not found`) + if (!showStyleBase) throw new Error(`ShowStyleBase "${showStyleBaseId}" not found`) - const showStyleVariants = allShowStyleVariants.filter((v) => { - if (data.showStyleVariantIds) return data.showStyleVariantIds.includes(v._id) - else return true - }) - if (showStyleVariants.length === 0) throw new Error(`No ShowStyleVariants found for ${data.showStyleBaseId}`) + const showStyleVariants = allShowStyleVariants.filter( + (v) => !ingestInfo.limitToShowStyleVariantIds || ingestInfo.limitToShowStyleVariantIds.includes(v._id) + ) + if (showStyleVariants.length === 0) throw new Error(`No ShowStyleVariants found for ${showStyleBaseId}`) const adlibIdsToRemove = new Set(allOldAdLibPieces.map((p) => p._id)) const actionIdsToRemove = new Set(allOldAdLibActions.map((p) => p._id)) @@ -74,7 +138,7 @@ export async function handleBucketItemImport(context: JobContext, data: BucketIt if (!showStyleCompound) throw new Error(`Unable to create a ShowStyleCompound for ${showStyleBase._id}, ${showStyleVariant._id} `) - const rawAdlib = generateBucketAdlibForVariant(context, blueprint, showStyleCompound, data.payload) + const rawAdlib = generateBucketAdlibForVariant(context, blueprint, showStyleCompound, ingestInfo.payload) if (rawAdlib) { const importVersions: RundownImportVersions = { @@ -87,7 +151,7 @@ export async function handleBucketItemImport(context: JobContext, data: BucketIt // Cache the newRank, so we only have to calculate it once: if (newRank === undefined) { - newRank = (await calculateHighestRankInBucket(context, data.bucketId)) + 1 + newRank = (await calculateHighestRankInBucket(context, bucketId)) + 1 } else { newRank++ } @@ -105,9 +169,9 @@ export async function handleBucketItemImport(context: JobContext, data: BucketIt context, showStyleCompound, rawAdlib, - data.payload.externalId, + ingestInfo, blueprint.blueprintId, - data.bucketId, + bucketId, newRank, importVersions ) @@ -125,9 +189,9 @@ export async function handleBucketItemImport(context: JobContext, data: BucketIt context, showStyleCompound, rawAdlib, - data.payload.externalId, + ingestInfo, blueprint.blueprintId, - data.bucketId, + bucketId, newRank, importVersions ) diff --git a/packages/job-worker/src/ingest/expectedPackages.ts b/packages/job-worker/src/ingest/expectedPackages.ts index bf25a331149..1950944487f 100644 --- a/packages/job-worker/src/ingest/expectedPackages.ts +++ b/packages/job-worker/src/ingest/expectedPackages.ts @@ -431,6 +431,7 @@ export function setDefaultIdOnExpectedPackages(expectedPackages: ExpectedPackage // Fill in ids of unnamed expectedPackage if (expectedPackages) { for (let i = 0; i < expectedPackages.length; i++) { + // TODO - make existing _id 'safe' to be an '_id' field? const expectedPackage = expectedPackages[i] if (!expectedPackage._id) { expectedPackage._id = `__index${i}` diff --git a/packages/job-worker/src/ingest/packageInfo.ts b/packages/job-worker/src/ingest/packageInfo.ts index 0cd651a8005..360e988730a 100644 --- a/packages/job-worker/src/ingest/packageInfo.ts +++ b/packages/job-worker/src/ingest/packageInfo.ts @@ -2,7 +2,6 @@ import { ExpectedPackageDBType } from '@sofie-automation/corelib/dist/dataModel/ import { SegmentId } from '@sofie-automation/corelib/dist/dataModel/Ids' import { ExpectedPackagesRegenerateProps, - PackageInfosUpdatedBucketItemProps, PackageInfosUpdatedRundownProps, } from '@sofie-automation/corelib/dist/worker/ingest' import { logger } from '../logging' @@ -106,17 +105,3 @@ export async function handleUpdatedPackageInfoForRundown( } ) } - -/** - * Some PackageInfos have been updated, regenerate any Parts which depend on these PackageInfos - */ -export async function handleUpdatedPackageInfoForBucketItem( - context: JobContext, - data: PackageInfosUpdatedBucketItemProps -): Promise { - if (data.packageIds.length === 0) { - return - } - - // TODO -} diff --git a/packages/job-worker/src/workers/ingest/jobs.ts b/packages/job-worker/src/workers/ingest/jobs.ts index 15c3eb5eacb..c5360ae7b1a 100644 --- a/packages/job-worker/src/workers/ingest/jobs.ts +++ b/packages/job-worker/src/workers/ingest/jobs.ts @@ -29,11 +29,7 @@ import { handleUpdatedSegment, handleUpdatedSegmentRanks, } from '../../ingest/ingestSegmentJobs' -import { - handleExpectedPackagesRegenerate, - handleUpdatedPackageInfoForBucketItem, - handleUpdatedPackageInfoForRundown, -} from '../../ingest/packageInfo' +import { handleExpectedPackagesRegenerate, handleUpdatedPackageInfoForRundown } from '../../ingest/packageInfo' import { handleBucketActionModify, handleBucketActionRegenerateExpectedPackages, @@ -42,7 +38,7 @@ import { handleBucketRemoveAdlibAction, handleBucketRemoveAdlibPiece, } from '../../ingest/bucket/bucketAdlibs' -import { handleBucketItemImport } from '../../ingest/bucket/import' +import { handleBucketItemImport, handleBucketItemRegenerate } from '../../ingest/bucket/import' type ExecutableFunction = ( context: JobContext, @@ -79,12 +75,12 @@ export const ingestJobHandlers: IngestJobHandlers = { [IngestJobs.ExpectedPackagesRegenerate]: handleExpectedPackagesRegenerate, [IngestJobs.PackageInfosUpdatedRundown]: handleUpdatedPackageInfoForRundown, - [IngestJobs.PackageInfosUpdatedBucketItem]: handleUpdatedPackageInfoForBucketItem, [IngestJobs.UserRemoveRundown]: handleUserRemoveRundown, [IngestJobs.UserUnsyncRundown]: handleUserUnsyncRundown, [IngestJobs.BucketItemImport]: handleBucketItemImport, + [IngestJobs.BucketItemRegenerate]: handleBucketItemRegenerate, [IngestJobs.BucketActionRegenerateExpectedPackages]: handleBucketActionRegenerateExpectedPackages, [IngestJobs.BucketActionModify]: handleBucketActionModify, [IngestJobs.BucketPieceModify]: handleBucketPieceModify,