@@ -175,38 +175,41 @@ export async function updateExpectedPackagesForBucketAdLibAction(
175175export 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