Skip to content

Commit

Permalink
chore: rename parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 11, 2023
1 parent f156148 commit 0a35c81
Show file tree
Hide file tree
Showing 27 changed files with 326 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { isTooCloseToAutonext } from '../../playout/lib'
import { PlayoutModel } from '../../playout/model/PlayoutModel'
import { WatchedPackagesHelper } from '../context/watchedPackages'
import { MockJobContext, setupDefaultJobEnvironment } from '../../__mocks__/context'
import { runJobWithPlayoutCache } from '../../playout/lock'
import { runJobWithPlayoutModel } from '../../playout/lock'
import { defaultRundownPlaylist } from '../../__mocks__/defaultCollectionObjects'
import { protectString, unprotectString } from '@sofie-automation/corelib/dist/protectedString'
import { clone, getRandomId, literal, normalizeArrayToMapFunc, omit } from '@sofie-automation/corelib/dist/lib'
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('Test blueprint api context', () => {
playlistId: RundownPlaylistId,
fcn: (playoutModel: PlayoutModel) => Promise<T>
): Promise<T> {
return runJobWithPlayoutCache(context, { playlistId }, null, fcn)
return runJobWithPlayoutModel(context, { playlistId }, null, fcn)
}

async function setupMyDefaultRundown(): Promise<{
Expand Down
4 changes: 2 additions & 2 deletions packages/job-worker/src/ingest/__tests__/ingest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { handleActivateRundownPlaylist } from '../../playout/activePlaylistJobs'
import { PartInstanceId, SegmentId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { getSelectedPartInstances } from '../../playout/__tests__/lib'
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
import { runJobWithPlayoutCache } from '../../playout/lock'
import { runJobWithPlayoutModel } from '../../playout/lock'
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
import { insertQueuedPartWithPieces } from '../../playout/adlibUtils'
import { IngestJobs, RemoveOrphanedSegmentsProps } from '@sofie-automation/corelib/dist/worker/ingest'
Expand Down Expand Up @@ -1999,7 +1999,7 @@ describe('Test ingest actions for rundowns and segments', () => {
})

const doQueuePart = async (): Promise<PartInstanceId> =>
runJobWithPlayoutCache(
runJobWithPlayoutModel(
context,
{
playlistId: rundown.playlistId,
Expand Down
4 changes: 2 additions & 2 deletions packages/job-worker/src/ingest/__tests__/updateNext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { protectString } from '@sofie-automation/corelib/dist/protectedString'
import { saveIntoDb } from '../../db/changes'
import { ensureNextPartIsValid as ensureNextPartIsValidRaw } from '../updateNext'
import { MockJobContext, setupDefaultJobEnvironment } from '../../__mocks__/context'
import { runJobWithPlayoutCache } from '../../playout/lock'
import { runJobWithPlayoutModel } from '../../playout/lock'

jest.mock('../../playout/setNext')
import { setNextPart } from '../../playout/setNext'
Expand Down Expand Up @@ -344,7 +344,7 @@ describe('ensureNextPartIsValid', () => {
})
}
async function ensureNextPartIsValid() {
await runJobWithPlayoutCache(context, { playlistId: rundownPlaylistId }, null, async (cache) =>
await runJobWithPlayoutModel(context, { playlistId: rundownPlaylistId }, null, async (cache) =>
ensureNextPartIsValidRaw(context, cache)
)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/job-worker/src/ingest/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getRundown } from './lib'
import { JobContext } from '../jobs'
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
import { runJobWithPlaylistLock, runWithPlaylistCache } from '../playout/lock'
import { runJobWithPlaylistLock, runWithPlayoutModel } from '../playout/lock'
import { removeSegmentContents } from './cleanup'
import { CommitIngestData } from './lock'
import { groupByToMap, groupByToMapFunc, normalizeArrayToMap } from '@sofie-automation/corelib/dist/lib'
Expand Down Expand Up @@ -493,7 +493,7 @@ export async function updatePlayoutAfterChangingRundownInPlaylist(
insertedRundown: ReadonlyDeep<DBRundown> | null
): Promise<void> {
// ensure the 'old' playout is updated to remove any references to the rundown
await runWithPlaylistCache(context, playlist, playlistLock, null, async (playoutCache) => {
await runWithPlayoutModel(context, playlist, playlistLock, null, async (playoutCache) => {
if (playoutCache.Rundowns.length === 0) {
if (playoutCache.Playlist.activationId)
throw new Error(`RundownPlaylist "${playoutCache.PlaylistId}" has no contents but is active...`)
Expand Down
18 changes: 9 additions & 9 deletions packages/job-worker/src/playout/__tests__/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { removeRundownFromDb } from '../../rundownPlaylists'
import { setupDefaultRundownPlaylist, setupMockShowStyleCompound } from '../../__mocks__/presetCollections'
import { activateRundownPlaylist } from '../activePlaylistActions'
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { runJobWithPlayoutCache } from '../lock'
import { runJobWithPlayoutModel } from '../lock'
import { runWithRundownLock } from '../../ingest/lock'

jest.mock('../../peripheralDevice')
Expand Down Expand Up @@ -48,26 +48,26 @@ describe('Playout Actions', () => {
expect(executePeripheralDeviceFunctionMock).toHaveBeenCalledTimes(0)

// Activating a rundown, to rehearsal
await runJobWithPlayoutCache(context, { playlistId: playlistId0 }, null, async (cache) =>
activateRundownPlaylist(context, cache, true)
await runJobWithPlayoutModel(context, { playlistId: playlistId0 }, null, async (playoutModel) =>
activateRundownPlaylist(context, playoutModel, true)
)
await expect(getPlaylist0()).resolves.toMatchObject({
activationId: expect.stringMatching(/^randomId/),
rehearsal: true,
})

// Activating a rundown
await runJobWithPlayoutCache(context, { playlistId: playlistId0 }, null, async (cache) =>
activateRundownPlaylist(context, cache, false)
await runJobWithPlayoutModel(context, { playlistId: playlistId0 }, null, async (playoutModel) =>
activateRundownPlaylist(context, playoutModel, false)
)
await expect(getPlaylist0()).resolves.toMatchObject({
activationId: expect.stringMatching(/^randomId/),
rehearsal: false,
})

// Activating a rundown, back to rehearsal
await runJobWithPlayoutCache(context, { playlistId: playlistId0 }, null, async (cache) =>
activateRundownPlaylist(context, cache, true)
await runJobWithPlayoutModel(context, { playlistId: playlistId0 }, null, async (playoutModel) =>
activateRundownPlaylist(context, playoutModel, true)
)
await expect(getPlaylist0()).resolves.toMatchObject({
activationId: expect.stringMatching(/^randomId/),
Expand All @@ -78,8 +78,8 @@ describe('Playout Actions', () => {

// Activating another rundown
await expect(
runJobWithPlayoutCache(context, { playlistId: playlistId1 }, null, async (cache) =>
activateRundownPlaylist(context, cache, false)
runJobWithPlayoutModel(context, { playlistId: playlistId1 }, null, async (playoutModel) =>
activateRundownPlaylist(context, playoutModel, false)
)
).rejects.toMatchToString(/only one rundown can be active/i)

Expand Down
34 changes: 17 additions & 17 deletions packages/job-worker/src/playout/__tests__/infinites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { candidatePartIsAfterPreviewPartInstance } from '../infinites'
import { setupDefaultRundownPlaylist, setupMockShowStyleCompound } from '../../__mocks__/presetCollections'
import { getRandomId } from '@sofie-automation/corelib/dist/lib'
import { DBRundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
import { runJobWithPlayoutCache } from '../lock'
import { runJobWithPlayoutModel } from '../lock'
import { wrapPartToTemporaryInstance } from '../../__mocks__/partinstance'
import { protectString } from '@sofie-automation/corelib/dist/protectedString'

Expand All @@ -19,7 +19,7 @@ describe('canContinueAdlibOnEndInfinites', () => {
await setupMockShowStyleCompound(context)
})

async function wrapWithCache<T>(
async function wrapWithPlayoutModel<T>(
fcn: (
playoutModel: PlayoutModel,
playlist: SetRequired<ReadonlyDeep<DBRundownPlaylist>, 'activationId'>
Expand All @@ -42,17 +42,17 @@ describe('canContinueAdlibOnEndInfinites', () => {
const rundown = (await context.mockCollections.Rundowns.findOne(defaultSetup.rundownId)) as DBRundown
expect(rundown).toBeTruthy()

return runJobWithPlayoutCache(context, { playlistId: tmpPlaylist._id }, null, async (cache) => {
const playlist = cache.Playlist as SetRequired<ReadonlyDeep<DBRundownPlaylist>, 'activationId'>
return runJobWithPlayoutModel(context, { playlistId: tmpPlaylist._id }, null, async (playoutModel) => {
const playlist = playoutModel.Playlist as SetRequired<ReadonlyDeep<DBRundownPlaylist>, 'activationId'>
if (!playlist.activationId) throw new Error('Missing activationId')
return fcn(cache, playlist)
return fcn(playoutModel, playlist)
})
}

test('Basic case', async () => {
await wrapWithCache(async (cache, playlist) => {
const orderedSegments = cache.getAllOrderedSegments()
const orderedParts = cache.getAllOrderedParts()
await wrapWithPlayoutModel(async (playoutModel, playlist) => {
const orderedSegments = playoutModel.getAllOrderedSegments()
const orderedParts = playoutModel.getAllOrderedParts()
expect(orderedParts.length).toBeGreaterThan(2)

// At beginning
Expand Down Expand Up @@ -98,9 +98,9 @@ describe('canContinueAdlibOnEndInfinites', () => {
})

test('No previousPartInstance', async () => {
await wrapWithCache(async (cache, _playlist) => {
const orderedSegments = cache.getAllOrderedSegments()
const orderedParts = cache.getAllOrderedParts()
await wrapWithPlayoutModel(async (playoutModel, _playlist) => {
const orderedSegments = playoutModel.getAllOrderedSegments()
const orderedParts = playoutModel.getAllOrderedParts()

expect(
candidatePartIsAfterPreviewPartInstance(context, orderedSegments, undefined, orderedParts[1])
Expand All @@ -109,9 +109,9 @@ describe('canContinueAdlibOnEndInfinites', () => {
})

test('Is before', async () => {
await wrapWithCache(async (cache, playlist) => {
const orderedSegments = cache.getAllOrderedSegments()
const orderedParts = cache.getAllOrderedParts()
await wrapWithPlayoutModel(async (playoutModel, playlist) => {
const orderedSegments = playoutModel.getAllOrderedSegments()
const orderedParts = playoutModel.getAllOrderedParts()
expect(orderedParts.length).toBeGreaterThan(2)

// At beginning
Expand Down Expand Up @@ -147,9 +147,9 @@ describe('canContinueAdlibOnEndInfinites', () => {
})

test('Orphaned PartInstance', async () => {
await wrapWithCache(async (cache, playlist) => {
const orderedSegments = cache.getAllOrderedSegments()
const orderedParts = cache.getAllOrderedParts()
await wrapWithPlayoutModel(async (playoutModel, playlist) => {
const orderedSegments = playoutModel.getAllOrderedSegments()
const orderedParts = playoutModel.getAllOrderedParts()
expect(orderedParts.length).toBeGreaterThan(2)

const candidatePart = {
Expand Down
29 changes: 19 additions & 10 deletions packages/job-worker/src/playout/__tests__/timeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { handleTakeNextPart } from '../take'
import { handleActivateHold } from '../holdJobs'
import { handleActivateRundownPlaylist, handleDeactivateRundownPlaylist } from '../activePlaylistJobs'
import { fixSnapshot } from '../../__mocks__/helpers/snapshot'
import { runJobWithPlayoutCache } from '../lock'
import { runJobWithPlayoutModel } from '../lock'
import { updateTimeline } from '../timeline/generate'
import { getSelectedPartInstances, getSortedPartsForRundown } from './lib'
import { PieceLifespan, IBlueprintPieceType, Time } from '@sofie-automation/blueprints-integration'
Expand Down Expand Up @@ -436,14 +436,14 @@ async function doDeactivatePlaylist(context: MockJobContext, playlistId: Rundown

/** perform an update of the timeline */
async function doUpdateTimeline(context: MockJobContext, playlistId: RundownPlaylistId, forceNowToTime?: Time) {
await runJobWithPlayoutCache(
await runJobWithPlayoutModel(
context,
{
playlistId: playlistId,
},
null,
async (cache) => {
await updateTimeline(context, cache, forceNowToTime)
async (playoutModel) => {
await updateTimeline(context, playoutModel, forceNowToTime)
}
)
}
Expand Down Expand Up @@ -540,8 +540,8 @@ describe('Timeline', () => {
// })
}

await runJobWithPlayoutCache(context, { playlistId: playlistId0 }, null, async (cache) => {
await updateTimeline(context, cache)
await runJobWithPlayoutModel(context, { playlistId: playlistId0 }, null, async (playoutModel) => {
await updateTimeline(context, playoutModel)
})

expect(fixSnapshot(await context.directCollections.Timelines.findFetch())).toMatchSnapshot()
Expand Down Expand Up @@ -1131,14 +1131,23 @@ describe('Timeline', () => {

describe('Adlib pieces', () => {
async function doStartAdlibPiece(playlistId: RundownPlaylistId, adlibSource: AdLibPiece) {
await runJobWithPlayoutCache(context, { playlistId }, null, async (cache) => {
const currentPartInstance = cache.CurrentPartInstance as PlayoutPartInstanceModel
await runJobWithPlayoutModel(context, { playlistId }, null, async (playoutModel) => {
const currentPartInstance = playoutModel.CurrentPartInstance as PlayoutPartInstanceModel
expect(currentPartInstance).toBeTruthy()

const rundown = cache.getRundown(currentPartInstance.PartInstance.rundownId) as PlayoutRundownModel
const rundown = playoutModel.getRundown(
currentPartInstance.PartInstance.rundownId
) as PlayoutRundownModel
expect(rundown).toBeTruthy()

return innerStartOrQueueAdLibPiece(context, cache, rundown, false, currentPartInstance, adlibSource)
return innerStartOrQueueAdLibPiece(
context,
playoutModel,
rundown,
false,
currentPartInstance,
adlibSource
)
})
}

Expand Down
48 changes: 24 additions & 24 deletions packages/job-worker/src/playout/activePlaylistJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ResetRundownPlaylistProps,
} from '@sofie-automation/corelib/dist/worker/studio'
import { JobContext } from '../jobs'
import { runJobWithPlayoutCache } from './lock'
import { runJobWithPlayoutModel } from './lock'
import { resetRundownPlaylist } from './lib'
import { updateTimeline } from './timeline/generate'
import { getActiveRundownPlaylistsInStudioFromDb } from '../studio/lib'
Expand Down Expand Up @@ -43,19 +43,19 @@ export async function handlePrepareRundownPlaylistForBroadcast(
context: JobContext,
data: PrepareRundownForBroadcastProps
): Promise<void> {
return runJobWithPlayoutCache(
return runJobWithPlayoutModel(
context,
data,
async (cache) => {
const playlist = cache.Playlist
async (playoutModel) => {
const playlist = playoutModel.Playlist
if (playlist.activationId) throw UserError.create(UserErrorMessage.RundownAlreadyActive)

await checkNoOtherPlaylistsActive(context, playlist)
},
async (cache) => {
await resetRundownPlaylist(context, cache)
async (playoutModel) => {
await resetRundownPlaylist(context, playoutModel)

await activateRundownPlaylist(context, cache, true) // Activate rundownPlaylist (rehearsal)
await activateRundownPlaylist(context, playoutModel, true) // Activate rundownPlaylist (rehearsal)
}
)
}
Expand All @@ -66,11 +66,11 @@ export async function handlePrepareRundownPlaylistForBroadcast(
* Optionally activate the rundown at the end.
*/
export async function handleResetRundownPlaylist(context: JobContext, data: ResetRundownPlaylistProps): Promise<void> {
return runJobWithPlayoutCache(
return runJobWithPlayoutModel(
context,
data,
async (cache) => {
const playlist = cache.Playlist
async (playoutModel) => {
const playlist = playoutModel.Playlist
if (playlist.activationId && !playlist.rehearsal && !context.studio.settings.allowRundownResetOnAir) {
throw UserError.create(UserErrorMessage.RundownResetWhileActive)
}
Expand All @@ -87,7 +87,7 @@ export async function handleResetRundownPlaylist(context: JobContext, data: Rese
// Try deactivating everything in parallel, although there should only ever be one active
await Promise.allSettled(
anyOtherActivePlaylists.map(async (otherRundownPlaylist) =>
runJobWithPlayoutCache(
runJobWithPlayoutModel(
context,
// 'forceResetAndActivateRundownPlaylist',
{ playlistId: otherRundownPlaylist._id },
Expand All @@ -109,15 +109,15 @@ export async function handleResetRundownPlaylist(context: JobContext, data: Rese
}
}
},
async (cache) => {
await resetRundownPlaylist(context, cache)
async (playoutModel) => {
await resetRundownPlaylist(context, playoutModel)

if (data.activate) {
// Do the activation
await activateRundownPlaylist(context, cache, data.activate !== 'active') // Activate rundown
} else if (cache.Playlist.activationId) {
await activateRundownPlaylist(context, playoutModel, data.activate !== 'active') // Activate rundown
} else if (playoutModel.Playlist.activationId) {
// Only update the timeline if this is the active playlist
await updateTimeline(context, cache)
await updateTimeline(context, playoutModel)
}
}
)
Expand All @@ -130,16 +130,16 @@ export async function handleActivateRundownPlaylist(
context: JobContext,
data: ActivateRundownPlaylistProps
): Promise<void> {
return runJobWithPlayoutCache(
return runJobWithPlayoutModel(
context,
// 'activateRundownPlaylist',
data,
async (cache) => {
const playlist = cache.Playlist
async (playoutModel) => {
const playlist = playoutModel.Playlist
await checkNoOtherPlaylistsActive(context, playlist)
},
async (cache) => {
await activateRundownPlaylist(context, cache, data.rehearsal)
async (playoutModel) => {
await activateRundownPlaylist(context, playoutModel, data.rehearsal)
}
)
}
Expand All @@ -151,13 +151,13 @@ export async function handleDeactivateRundownPlaylist(
context: JobContext,
data: DeactivateRundownPlaylistProps
): Promise<void> {
return runJobWithPlayoutCache(
return runJobWithPlayoutModel(
context,
// 'deactivateRundownPlaylist',
data,
null,
async (cache) => {
await deactivateRundownPlaylist(context, cache)
async (playoutModel) => {
await deactivateRundownPlaylist(context, playoutModel)
}
)
}
Loading

0 comments on commit 0a35c81

Please sign in to comment.