Skip to content

Commit 73c8ede

Browse files
committed
wip: coresystem settings
1 parent 712f7ce commit 73c8ede

File tree

19 files changed

+392
-147
lines changed

19 files changed

+392
-147
lines changed

meteor/__mocks__/helpers/database.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ export async function setupMockCore(doc?: Partial<ICoreSystem>): Promise<ICoreSy
171171
version: '0.0.0',
172172
previousVersion: '0.0.0',
173173
serviceMessages: {},
174+
settingsWithOverrides: wrapDefaultObject({
175+
cron: {
176+
casparCGRestart: {
177+
enabled: true,
178+
},
179+
storeRundownSnapshots: {
180+
enabled: false,
181+
},
182+
},
183+
support: {
184+
message: '',
185+
},
186+
evaluationsMessage: {
187+
enabled: false,
188+
heading: '',
189+
message: '',
190+
},
191+
}),
174192
lastBlueprintConfig: undefined,
175193
}
176194
const coreSystem = _.extend(defaultCore, doc)

meteor/server/__tests__/api/serviceMessages/serviceMessagesApi.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from '@sofie-automation/meteor-lib/dist/collections/CoreSystem'
1010
import { CoreSystem } from '../../../collections'
1111
import { SupressLogMessages } from '../../../../__mocks__/suppressLogging'
12+
import { wrapDefaultObject } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
1213

1314
function convertExternalToServiceMessage(message: ExternalServiceMessage): ServiceMessage {
1415
return {
@@ -42,6 +43,7 @@ const fakeCoreSystem: ICoreSystem = {
4243
version: '3',
4344
previousVersion: null,
4445
serviceMessages: {},
46+
settingsWithOverrides: wrapDefaultObject({} as any),
4547
lastBlueprintConfig: undefined,
4648
}
4749

meteor/server/collections/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,13 @@ export const CoreSystem = createAsyncOnlyMongoCollection<ICoreSystem>(Collection
6767
if (!access.update) return logNotAllowed('CoreSystem', access.reason)
6868

6969
return allowOnlyFields(doc, fields, [
70-
'support',
7170
'systemInfo',
7271
'name',
7372
'logLevel',
7473
'apm',
75-
'cron',
7674
'logo',
77-
'evaluations',
7875
'blueprintId',
76+
'settingsWithOverrides',
7977
])
8078
},
8179
})

meteor/server/coreSystem/index.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import { getEnvLogLevel, logger, LogLevel, setLogLevel } from '../logging'
1010
const PackageInfo = require('../../package.json')
1111
import { startAgent } from '../api/profiler/apm'
1212
import { profiler } from '../api/profiler'
13-
import { TMP_TSR_VERSION } from '@sofie-automation/blueprints-integration'
13+
import { ICoreSystemSettings, TMP_TSR_VERSION } from '@sofie-automation/blueprints-integration'
1414
import { getAbsolutePath } from '../lib'
1515
import * as fs from 'fs/promises'
1616
import path from 'path'
1717
import { checkDatabaseVersions } from './checkDatabaseVersions'
1818
import PLazy from 'p-lazy'
1919
import { getCoreSystemAsync } from './collection'
20+
import { wrapDefaultObject } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
2021

2122
export { PackageInfo }
2223

@@ -59,11 +60,24 @@ async function initializeCoreSystem() {
5960
enabled: false,
6061
transactionSampleRate: -1,
6162
},
62-
cron: {
63-
casparCGRestart: {
64-
enabled: true,
63+
settingsWithOverrides: wrapDefaultObject<ICoreSystemSettings>({
64+
cron: {
65+
casparCGRestart: {
66+
enabled: true,
67+
},
68+
storeRundownSnapshots: {
69+
enabled: false,
70+
},
6571
},
66-
},
72+
support: {
73+
message: '',
74+
},
75+
evaluationsMessage: {
76+
enabled: false,
77+
heading: '',
78+
message: '',
79+
},
80+
}),
6781
lastBlueprintConfig: undefined,
6882
})
6983

meteor/server/cronjobs.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ import { deferAsync, normalizeArrayToMap } from '@sofie-automation/corelib/dist/
1818
import { getCoreSystemAsync } from './coreSystem/collection'
1919
import { cleanupOldDataInner } from './api/cleanup'
2020
import { CollectionCleanupResult } from '@sofie-automation/meteor-lib/dist/api/system'
21-
import { ICoreSystem } from '@sofie-automation/meteor-lib/dist/collections/CoreSystem'
21+
import { ICoreSystemSettings } from '@sofie-automation/shared-lib/dist/core/model/CoreSystemSettings'
2222
import { executePeripheralDeviceFunctionWithCustomTimeout } from './api/peripheralDevice/executeFunction'
2323
import {
2424
interpollateTranslation,
2525
isTranslatableMessage,
2626
translateMessage,
2727
} from '@sofie-automation/corelib/dist/TranslatableMessage'
28+
import { applyAndValidateOverrides } from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
2829

2930
const lowPrioFcn = (fcn: () => any) => {
3031
// Do it at a random time in the future:
@@ -49,15 +50,17 @@ export async function nightlyCronjobInner(): Promise<void> {
4950
logger.info('Nightly cronjob: starting...')
5051
const system = await getCoreSystemAsync()
5152

53+
const systemSettings = system && applyAndValidateOverrides(system.settingsWithOverrides).obj
54+
5255
await Promise.allSettled([
5356
cleanupOldDataCronjob().catch((error) => {
5457
logger.error(`Cronjob: Error when cleaning up old data: ${stringifyError(error)}`)
5558
logger.error(error)
5659
}),
57-
restartCasparCG(system, previousLastNightlyCronjob).catch((e) => {
60+
restartCasparCG(systemSettings, previousLastNightlyCronjob).catch((e) => {
5861
logger.error(`Cron: Restart CasparCG error: ${stringifyError(e)}`)
5962
}),
60-
storeSnapshots(system).catch((e) => {
63+
storeSnapshots(systemSettings).catch((e) => {
6164
logger.error(`Cron: Rundown Snapshots error: ${stringifyError(e)}`)
6265
}),
6366
])
@@ -81,8 +84,8 @@ async function cleanupOldDataCronjob() {
8184

8285
const CASPARCG_LAST_SEEN_PERIOD_MS = 3 * 60 * 1000 // Note: this must be higher than the ping interval used by playout-gateway
8386

84-
async function restartCasparCG(system: ICoreSystem | undefined, previousLastNightlyCronjob: number) {
85-
if (!system?.cron?.casparCGRestart?.enabled) return
87+
async function restartCasparCG(systemSettings: ICoreSystemSettings | undefined, previousLastNightlyCronjob: number) {
88+
if (!systemSettings?.cron?.casparCGRestart?.enabled) return
8689

8790
let shouldRetryAttempt = false
8891
const ps: Array<Promise<any>> = []
@@ -176,10 +179,10 @@ async function restartCasparCG(system: ICoreSystem | undefined, previousLastNigh
176179
}
177180
}
178181

179-
async function storeSnapshots(system: ICoreSystem | undefined) {
180-
if (system?.cron?.storeRundownSnapshots?.enabled) {
181-
const filter = system.cron.storeRundownSnapshots.rundownNames?.length
182-
? { name: { $in: system.cron.storeRundownSnapshots.rundownNames } }
182+
async function storeSnapshots(systemSettings: ICoreSystemSettings | undefined) {
183+
if (systemSettings?.cron?.storeRundownSnapshots?.enabled) {
184+
const filter = systemSettings.cron.storeRundownSnapshots.rundownNames?.length
185+
? { name: { $in: systemSettings.cron.storeRundownSnapshots.rundownNames } }
183186
: {}
184187

185188
const playlists = await RundownPlaylists.findFetchAsync(filter)

meteor/server/logo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ logoRouter.get('/', async (ctx) => {
1313
const logo = core?.logo ?? SofieLogo.Default
1414

1515
const paths: Record<SofieLogo, string> = {
16-
[SofieLogo.Default]: '/images/sofie-logo.svg',
16+
[SofieLogo.Default]: '/images/sofie-logo-default.svg',
1717
[SofieLogo.Pride]: '/images/sofie-logo-pride.svg',
1818
[SofieLogo.Norway]: '/images/sofie-logo-norway.svg',
1919
[SofieLogo.Christmas]: '/images/sofie-logo-christmas.svg',

meteor/server/migration/X_X_X.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addMigrationSteps } from './databaseMigration'
22
import { CURRENT_SYSTEM_VERSION } from './currentSystemVersion'
3-
import { Studios, TriggeredActions } from '../collections'
3+
import { CoreSystem, Studios, TriggeredActions } from '../collections'
44
import {
55
convertObjectIntoOverrides,
66
wrapDefaultObject,
@@ -12,6 +12,8 @@ import {
1212
IStudioSettings,
1313
} from '@sofie-automation/corelib/dist/dataModel/Studio'
1414
import { DEFAULT_CORE_TRIGGER_IDS } from './upgrades/defaultSystemActionTriggers'
15+
import { ICoreSystem } from '@sofie-automation/meteor-lib/dist/collections/CoreSystem'
16+
import { ICoreSystemSettings } from '@sofie-automation/shared-lib/dist/core/model/CoreSystemSettings'
1517

1618
/*
1719
* **************************************************************************************
@@ -258,4 +260,78 @@ export const addSteps = addMigrationSteps(CURRENT_SYSTEM_VERSION, [
258260
}
259261
},
260262
},
263+
264+
{
265+
id: `convert CoreSystem.settingsWithOverrides`,
266+
canBeRunAutomatically: true,
267+
validate: async () => {
268+
const systems = await CoreSystem.findFetchAsync({
269+
settingsWithOverrides: { $exists: false },
270+
})
271+
272+
if (systems.length > 0) {
273+
return 'settings must be converted to an ObjectWithOverrides'
274+
}
275+
276+
return false
277+
},
278+
migrate: async () => {
279+
const systems = await CoreSystem.findFetchAsync({
280+
settingsWithOverrides: { $exists: false },
281+
})
282+
283+
for (const system of systems) {
284+
const oldSystem = system as ICoreSystem as PartialOldICoreSystem
285+
286+
const newSettings = wrapDefaultObject<ICoreSystemSettings>({
287+
cron: {
288+
casparCGRestart: {
289+
enabled: false,
290+
},
291+
storeRundownSnapshots: {
292+
enabled: false,
293+
},
294+
...oldSystem.cron,
295+
},
296+
support: oldSystem.support ?? { message: '' },
297+
evaluationsMessage: oldSystem.evaluations ?? { enabled: false, heading: '', message: '' },
298+
})
299+
300+
await CoreSystem.updateAsync(system._id, {
301+
$set: {
302+
settingsWithOverrides: newSettings,
303+
},
304+
$unset: {
305+
cron: 1,
306+
support: 1,
307+
evaluations: 1,
308+
},
309+
})
310+
}
311+
},
312+
},
261313
])
314+
315+
interface PartialOldICoreSystem {
316+
/** Support info */
317+
support?: {
318+
message: string
319+
}
320+
321+
evaluations?: {
322+
enabled: boolean
323+
heading: string
324+
message: string
325+
}
326+
327+
/** Cron jobs running nightly */
328+
cron?: {
329+
casparCGRestart?: {
330+
enabled: boolean
331+
}
332+
storeRundownSnapshots?: {
333+
enabled: boolean
334+
rundownNames?: string[]
335+
}
336+
}
337+
}

meteor/server/migration/upgrades/system.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { updateTriggeredActionsForShowStyleBaseId } from './lib'
1313
import { CoreSystemId } from '@sofie-automation/corelib/dist/dataModel/Ids'
1414
import { DEFAULT_CORE_TRIGGERS } from './defaultSystemActionTriggers'
1515
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
16+
import { ICoreSystemSettings } from '@sofie-automation/shared-lib/dist/core/model/CoreSystemSettings'
1617

1718
export async function runUpgradeForCoreSystem(coreSystemId: CoreSystemId): Promise<void> {
1819
logger.info(`Running upgrade for CoreSystem`)
@@ -33,10 +34,11 @@ export async function runUpgradeForCoreSystem(coreSystemId: CoreSystemId): Promi
3334
result = generateDefaultSystemConfig()
3435
}
3536

37+
const coreSystemSettings: ICoreSystemSettings = result.settings
38+
3639
await CoreSystem.updateAsync(coreSystemId, {
3740
$set: {
38-
// 'sourceLayersWithOverrides.defaults': normalizeArray(result.sourceLayers, '_id'),
39-
// 'outputLayersWithOverrides.defaults': normalizeArray(result.outputLayers, '_id'),
41+
'settingsWithOverrides.defaults': coreSystemSettings,
4042
lastBlueprintConfig: {
4143
blueprintHash: blueprint?.blueprintHash ?? protectString('default'),
4244
blueprintId: blueprint?._id ?? protectString('default'),
@@ -83,6 +85,24 @@ async function loadCoreSystemAndBlueprint(coreSystemId: CoreSystemId) {
8385

8486
function generateDefaultSystemConfig(): BlueprintResultApplySystemConfig {
8587
return {
88+
settings: {
89+
cron: {
90+
casparCGRestart: {
91+
enabled: true,
92+
},
93+
storeRundownSnapshots: {
94+
enabled: false,
95+
},
96+
},
97+
support: {
98+
message: '',
99+
},
100+
evaluationsMessage: {
101+
enabled: false,
102+
heading: '',
103+
message: '',
104+
},
105+
},
86106
triggeredActions: Object.values<IBlueprintTriggeredActions>(DEFAULT_CORE_TRIGGERS),
87107
}
88108
}

meteor/server/publications/system.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@ meteorPublish(MeteorPubSub.coreSystem, async function (token: string | undefined
1515
fields: {
1616
// Include only specific fields in the result documents:
1717
_id: 1,
18-
support: 1,
1918
systemInfo: 1,
2019
apm: 1,
2120
name: 1,
2221
logLevel: 1,
2322
serviceMessages: 1,
2423
blueprintId: 1,
25-
cron: 1,
2624
logo: 1,
27-
evaluations: 1,
25+
settingsWithOverrides: 1,
2826
},
2927
})
3028
}

packages/blueprints-integration/src/api/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { IBlueprintTriggeredActions } from '../triggers'
22
import type { MigrationStepSystem } from '../migrations'
33
import type { BlueprintManifestBase, BlueprintManifestType } from './base'
44
import type { ICoreSystemApplyConfigContext } from '../context/systemApplyConfigContext'
5+
import type { ICoreSystemSettings } from '@sofie-automation/shared-lib/dist/core/model/CoreSystemSettings'
56

67
export interface SystemBlueprintManifest extends BlueprintManifestBase {
78
blueprintType: BlueprintManifestType.SYSTEM
@@ -38,8 +39,7 @@ export interface SystemBlueprintManifest extends BlueprintManifestBase {
3839
}
3940

4041
export interface BlueprintResultApplySystemConfig {
41-
// sourceLayers: ISourceLayer[]
42-
// outputLayers: IOutputLayer[]
42+
settings: ICoreSystemSettings
4343

4444
triggeredActions: IBlueprintTriggeredActions[]
4545
}

0 commit comments

Comments
 (0)