Skip to content

Commit

Permalink
fix(Cronjob): don't restart CasparCG using the nightly cronjob if the…
Browse files Browse the repository at this point in the history
…re's a Rundown active in the Studio

Skip until next day.
  • Loading branch information
jstarpl committed Jan 23, 2025
1 parent b51ee26 commit eb35f0e
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions meteor/server/cronjobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
translateMessage,
} from '@sofie-automation/corelib/dist/TranslatableMessage'
import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'

const lowPrioFcn = (fcn: () => any) => {
// Do it at a random time in the future:
Expand Down Expand Up @@ -90,20 +91,38 @@ async function restartCasparCG(systemSettings: ICoreSystemSettings | undefined,
let shouldRetryAttempt = false
const ps: Array<Promise<any>> = []

const casparcgAndParentDevices = (await PeripheralDevices.findFetchAsync(
{
type: PeripheralDeviceType.PLAYOUT,
subType: { $in: [PERIPHERAL_SUBTYPE_PROCESS, TSR.DeviceType.CASPARCG] },
},
{
projection: {
_id: 1,
subType: 1,
parentDeviceId: 1,
lastSeen: 1,
const [casparcgAndParentDevices, activePlaylists] = await Promise.all([
PeripheralDevices.findFetchAsync(
{
type: PeripheralDeviceType.PLAYOUT,
subType: { $in: [PERIPHERAL_SUBTYPE_PROCESS, TSR.DeviceType.CASPARCG] },
},
}
)) as Array<Pick<PeripheralDevice, '_id' | 'subType' | 'parentDeviceId' | 'lastSeen'>>
{
projection: {
_id: 1,
subType: 1,
parentDeviceId: 1,
lastSeen: 1,
studioAndConfigId: 1,
},
}
) as Promise<
Array<Pick<PeripheralDevice, '_id' | 'subType' | 'parentDeviceId' | 'lastSeen' | 'studioAndConfigId'>>
>,
RundownPlaylists.findFetchAsync(
{
activationId: {
$exists: true,
},
},
{
projection: {
_id: 1,
studioId: 1,
},
}
) as Promise<Array<Pick<DBRundownPlaylist, '_id' | 'studioId'>>>,
])

const deviceMap = normalizeArrayToMap(casparcgAndParentDevices, '_id')

Expand All @@ -128,6 +147,17 @@ async function restartCasparCG(systemSettings: ICoreSystemSettings | undefined,
continue
}

const activePlaylistUsingDevice = activePlaylists.find(
(playlist) => playlist.studioId === parentDevice.studioAndConfigId?.studioId
)
if (activePlaylistUsingDevice) {
logger.info(
`Cronjob: Skipping CasparCG device "${device._id}" with a parent device belonging to a Studio ("${activePlaylistUsingDevice.studioId}") with an active RundownPlaylist: "${activePlaylistUsingDevice._id}"`
)
// If a Rundown is active during "low season", it's proably best to just let it go until next "low season" the following day, don't retry
continue
}

if (parentDevice.lastSeen < getCurrentTime() - CASPARCG_LAST_SEEN_PERIOD_MS) {
logger.info(`Cronjob: Skipping CasparCG device "${device._id}" with offline parent device`)
shouldRetryAttempt = true
Expand Down

0 comments on commit eb35f0e

Please sign in to comment.