@@ -26,6 +26,7 @@ import {
26
26
translateMessage ,
27
27
} from '@sofie-automation/corelib/dist/TranslatableMessage'
28
28
import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
29
+ import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
29
30
30
31
const lowPrioFcn = ( fcn : ( ) => any ) => {
31
32
// Do it at a random time in the future:
@@ -90,20 +91,38 @@ async function restartCasparCG(systemSettings: ICoreSystemSettings | undefined,
90
91
let shouldRetryAttempt = false
91
92
const ps : Array < Promise < any > > = [ ]
92
93
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 ] } ,
104
99
} ,
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
+ ] )
107
126
108
127
const deviceMap = normalizeArrayToMap ( casparcgAndParentDevices , '_id' )
109
128
@@ -128,6 +147,17 @@ async function restartCasparCG(systemSettings: ICoreSystemSettings | undefined,
128
147
continue
129
148
}
130
149
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
+
131
161
if ( parentDevice . lastSeen < getCurrentTime ( ) - CASPARCG_LAST_SEEN_PERIOD_MS ) {
132
162
logger . info ( `Cronjob: Skipping CasparCG device "${ device . _id } " with offline parent device` )
133
163
shouldRetryAttempt = true
0 commit comments