Skip to content

Commit eb35f0e

Browse files
committed
fix(Cronjob): don't restart CasparCG using the nightly cronjob if there's a Rundown active in the Studio
Skip until next day.
1 parent b51ee26 commit eb35f0e

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

meteor/server/cronjobs.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
translateMessage,
2727
} from '@sofie-automation/corelib/dist/TranslatableMessage'
2828
import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
29+
import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
2930

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

93-
const casparcgAndParentDevices = (await PeripheralDevices.findFetchAsync(
94-
{
95-
type: PeripheralDeviceType.PLAYOUT,
96-
subType: { $in: [PERIPHERAL_SUBTYPE_PROCESS, TSR.DeviceType.CASPARCG] },
97-
},
98-
{
99-
projection: {
100-
_id: 1,
101-
subType: 1,
102-
parentDeviceId: 1,
103-
lastSeen: 1,
94+
const [casparcgAndParentDevices, activePlaylists] = await Promise.all([
95+
PeripheralDevices.findFetchAsync(
96+
{
97+
type: PeripheralDeviceType.PLAYOUT,
98+
subType: { $in: [PERIPHERAL_SUBTYPE_PROCESS, TSR.DeviceType.CASPARCG] },
10499
},
105-
}
106-
)) as Array<Pick<PeripheralDevice, '_id' | 'subType' | 'parentDeviceId' | 'lastSeen'>>
100+
{
101+
projection: {
102+
_id: 1,
103+
subType: 1,
104+
parentDeviceId: 1,
105+
lastSeen: 1,
106+
studioAndConfigId: 1,
107+
},
108+
}
109+
) as Promise<
110+
Array<Pick<PeripheralDevice, '_id' | 'subType' | 'parentDeviceId' | 'lastSeen' | 'studioAndConfigId'>>
111+
>,
112+
RundownPlaylists.findFetchAsync(
113+
{
114+
activationId: {
115+
$exists: true,
116+
},
117+
},
118+
{
119+
projection: {
120+
_id: 1,
121+
studioId: 1,
122+
},
123+
}
124+
) as Promise<Array<Pick<DBRundownPlaylist, '_id' | 'studioId'>>>,
125+
])
107126

108127
const deviceMap = normalizeArrayToMap(casparcgAndParentDevices, '_id')
109128

@@ -128,6 +147,17 @@ async function restartCasparCG(systemSettings: ICoreSystemSettings | undefined,
128147
continue
129148
}
130149

150+
const activePlaylistUsingDevice = activePlaylists.find(
151+
(playlist) => playlist.studioId === parentDevice.studioAndConfigId?.studioId
152+
)
153+
if (activePlaylistUsingDevice) {
154+
logger.info(
155+
`Cronjob: Skipping CasparCG device "${device._id}" with a parent device belonging to a Studio ("${activePlaylistUsingDevice.studioId}") with an active RundownPlaylist: "${activePlaylistUsingDevice._id}"`
156+
)
157+
// 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
158+
continue
159+
}
160+
131161
if (parentDevice.lastSeen < getCurrentTime() - CASPARCG_LAST_SEEN_PERIOD_MS) {
132162
logger.info(`Cronjob: Skipping CasparCG device "${device._id}" with offline parent device`)
133163
shouldRetryAttempt = true

0 commit comments

Comments
 (0)