Skip to content

Commit 3c6de9c

Browse files
committed
wip: bucket cleanup fix
1 parent c2cc615 commit 3c6de9c

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

packages/job-worker/src/ingest/bucket/bucketAdlibs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from '@sofie-automation/corelib/dist/worker/ingest'
1111
import {
1212
cleanUpExpectedPackagesForBucketAdLibs,
13-
cleanUpExpectedPackagesForBucketAdLibsActions,
1413
updateExpectedPackagesForBucketAdLibPiece,
1514
updateExpectedPackagesForBucketAdLibAction,
1615
} from '../expectedPackages'
@@ -59,7 +58,7 @@ export async function handleBucketRemoveAdlibAction(
5958
await Promise.all([
6059
context.directCollections.BucketAdLibActions.remove({ _id: { $in: idsToUpdate } }),
6160
cleanUpExpectedMediaItemForBucketAdLibActions(context, idsToUpdate),
62-
cleanUpExpectedPackagesForBucketAdLibsActions(context, action.bucketId, idsToUpdate),
61+
cleanUpExpectedPackagesForBucketAdLibs(context, action.bucketId, idsToUpdate),
6362
])
6463
}
6564

packages/job-worker/src/ingest/bucket/import.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { getSystemVersion } from '../../lib'
1212
import { BucketItemImportProps, BucketItemRegenerateProps } from '@sofie-automation/corelib/dist/worker/ingest'
1313
import {
1414
cleanUpExpectedPackagesForBucketAdLibs,
15-
cleanUpExpectedPackagesForBucketAdLibsActions,
1615
updateExpectedPackagesForBucketAdLibPiece,
1716
updateExpectedPackagesForBucketAdLibAction,
1817
} from '../expectedPackages'
@@ -253,7 +252,7 @@ async function regenerateBucketItemFromIngestInfo(
253252

254253
ps.push(
255254
cleanUpExpectedMediaItemForBucketAdLibActions(context, actionIdsToRemoveArray),
256-
cleanUpExpectedPackagesForBucketAdLibsActions(context, bucketId, actionIdsToRemoveArray),
255+
cleanUpExpectedPackagesForBucketAdLibs(context, bucketId, actionIdsToRemoveArray),
257256
context.directCollections.BucketAdLibActions.remove({ _id: { $in: actionIdsToRemoveArray } })
258257
)
259258
}

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

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -175,38 +175,41 @@ export async function updateExpectedPackagesForBucketAdLibAction(
175175
export async function cleanUpExpectedPackagesForBucketAdLibs(
176176
context: JobContext,
177177
bucketId: BucketId,
178-
adLibIds: PieceId[]
178+
adLibIds: Array<PieceId | AdLibActionId>
179179
): Promise<void> {
180180
if (adLibIds.length > 0) {
181-
await context.directCollections.ExpectedPackages.remove({
182-
studioId: context.studioId,
183-
bucketId: bucketId,
184-
// Note: This assumes that there is only one ingest source for each piece
185-
ingestSources: {
186-
$elemMatch: {
187-
fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB,
188-
pieceId: { $in: adLibIds },
181+
// Remove the claim for the adlibs from any expected packages in the db
182+
await context.directCollections.ExpectedPackages.update(
183+
{
184+
studioId: context.studioId,
185+
bucketId: bucketId,
186+
ingestSources: {
187+
$elemMatch: {
188+
fromPieceType: {
189+
$in: [ExpectedPackageDBType.BUCKET_ADLIB, ExpectedPackageDBType.BUCKET_ADLIB_ACTION],
190+
},
191+
pieceId: { $in: adLibIds },
192+
},
189193
},
190194
},
191-
})
192-
}
193-
}
194-
export async function cleanUpExpectedPackagesForBucketAdLibsActions(
195-
context: JobContext,
196-
bucketId: BucketId,
197-
adLibIds: AdLibActionId[]
198-
): Promise<void> {
199-
if (adLibIds.length > 0) {
195+
{
196+
$pull: {
197+
ingestSources: {
198+
fromPieceType: {
199+
$in: [ExpectedPackageDBType.BUCKET_ADLIB, ExpectedPackageDBType.BUCKET_ADLIB_ACTION],
200+
},
201+
pieceId: { $in: adLibIds },
202+
} as any, // nocommit - can we avoid this? Does this query even work?
203+
},
204+
}
205+
)
206+
207+
// Remove any expected packages that have now have no owners
200208
await context.directCollections.ExpectedPackages.remove({
201209
studioId: context.studioId,
202210
bucketId: bucketId,
203-
// Note: This assumes that there is only one ingest source for each piece
204-
ingestSources: {
205-
$elemMatch: {
206-
fromPieceType: ExpectedPackageDBType.BUCKET_ADLIB_ACTION,
207-
pieceId: { $in: adLibIds },
208-
},
209-
},
211+
ingestSources: { $size: 0 },
212+
// Future: these currently can't be referenced by playoutSources, but they could be in the future
210213
})
211214
}
212215
}

0 commit comments

Comments
 (0)