diff --git a/README.md b/README.md index 689440a8..234455f1 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Other useful commands: yarn start:single-app # Start the single-app in local-only mode, using packages from expectedPackages.json -yarn start:single-app -- -- --watchFiles=true --noCore=true +yarn start:single-app -- -- --watchFiles=true --noCore=true --logLevel=debug diff --git a/apps/package-manager/packages/generic/src/packageManager.ts b/apps/package-manager/packages/generic/src/packageManager.ts index e226855d..36be244b 100644 --- a/apps/package-manager/packages/generic/src/packageManager.ts +++ b/apps/package-manager/packages/generic/src/packageManager.ts @@ -69,6 +69,7 @@ import { GenerateExpectationApi } from './generateExpectations/api' import { PackageManagerSettings } from './generated/options' import * as NRK from './generateExpectations/nrk' +import { startTimer } from '@sofie-package-manager/api' export class PackageManagerHandler { public coreHandler!: CoreHandler @@ -76,7 +77,6 @@ export class PackageManagerHandler { public expectationManager: ExpectationManager - private expectedPackageCache: Map = new Map() public packageContainersCache: PackageContainers = {} private externalData: { packageContainers: PackageContainers; expectedPackages: ExpectedPackageWrap[] } = { @@ -228,6 +228,8 @@ export class PackageManagerHandler { this._triggerUpdatedExpectedPackagesTimeout = setTimeout(() => { this._triggerUpdatedExpectedPackagesTimeout = null + const timer = startTimer() + const packageContainers: PackageContainers = {} const expectedPackageSources: { sourceName: string @@ -296,6 +298,8 @@ export class PackageManagerHandler { } this.handleExpectedPackages(packageContainers, activePlaylist, activeRundowns, expectedPackageSources) + + this.logger.debug(`Took ${timer.get()} ms to handle updated expectedPackages`) }, 300) } @@ -317,21 +321,7 @@ export class PackageManagerHandler { } // Step 0: Save local cache: - this.expectedPackageCache = new Map() this.packageContainersCache = packageContainers - for (const exp of expectedPackages) { - // Note: There might be duplicates in expectedPackages - - const expId: ExpectedPackageId = exp.expectedPackage._id - - const existing = this.expectedPackageCache.get(expId) - if ( - !existing || - existing.priority > exp.priority // If the existing priority is lower (ie higher), replace it - ) { - this.expectedPackageCache.set(expId, exp) - } - } this.logger.debug( `Has ${expectedPackages.length} expectedPackages (${expectedPackageSources diff --git a/scripts/build-win32.mjs b/scripts/build-win32.mjs index 7977f57c..444960b9 100644 --- a/scripts/build-win32.mjs +++ b/scripts/build-win32.mjs @@ -93,18 +93,23 @@ if (!executableName) { const extraArgs = [] + const assets = [] + if (packageJson.name === '@single-app/app') { + assets.push(path.join(basePath, './node_modules/@sofie-automation/server-core-integration/package.json')) + assets.push(path.join(basePath, './package.json')) + } + + if (assets.length > 0) { extraArgs.push( '--assets', - [ - path.join(basePath, './node_modules/@sofie-automation/server-core-integration/package.json'), - path.join(basePath, './package.json'), - ].join(',') + assets.join(',') ) } await pkg.exec([ path.join(basePath, './dist/index.js'), + // '--debug', '--targets', 'node16-win-x64', '--output', diff --git a/scripts/cleanup-after-build32.mjs b/scripts/cleanup-after-build32.mjs index 17102f5e..a2c3fadc 100644 --- a/scripts/cleanup-after-build32.mjs +++ b/scripts/cleanup-after-build32.mjs @@ -7,7 +7,7 @@ import { promisify } from 'util' const glob = promisify(glob0) -const basePath = process.cwd() +const basePath = '.' console.log(`Cleaning up...`) @@ -21,7 +21,10 @@ console.log(`Remove unused files...`) const copiedFiles = [ ...(await glob(`${basePath}/apps/*/app/node_modules/@*/app/*`)), ...(await glob(`${basePath}/apps/*/app/node_modules/@*/generic/*`)), + ...(await glob(`${basePath}/node_modules/@parcel/watcher/build/**/*`)), ] + +console.log('copiedFiles', copiedFiles) for (const file of copiedFiles) { console.log(`Removing file: "${file}"`) ps.push(fse.rm(file, { recursive: true })) diff --git a/scripts/prepare-for-build32.js b/scripts/prepare-for-build32.js index a28e07f5..0f030a1c 100644 --- a/scripts/prepare-for-build32.js +++ b/scripts/prepare-for-build32.js @@ -2,6 +2,7 @@ const promisify = require('util').promisify const cp = require('child_process') const path = require('path') +const os = require('os') // const nexe = require('nexe') const exec = promisify(cp.exec) @@ -23,36 +24,60 @@ const packageJson = require(path.join(basePath, '/package.json')) // } ;(async () => { - log(`Collecting dependencies for ${packageJson.name}...`) - // List all Lerna packages: - const list = await exec('yarn lerna list -a --json') - const str = list.stdout - .replace(/^yarn run .*$/gm, '') - .replace(/^\$.*$/gm, '') - .replace(/^Done in.*$/gm, '') + // Collecting dependencies + { + log(`Collecting dependencies for ${packageJson.name}...`) + // List all Lerna packages: + const list = await exec('yarn lerna list -a --json') + const str = list.stdout + .replace(/^yarn run .*$/gm, '') + .replace(/^\$.*$/gm, '') + .replace(/^Done in.*$/gm, '') - const packages = JSON.parse(str) + const packages = JSON.parse(str) - await mkdirp(path.join(basePath, 'node_modules')) + await mkdirp(path.join(basePath, 'node_modules')) - // Copy the packages into node_modules: - const copiedFolders = [] - let ps = [] - for (const package0 of packages) { - if (package0.name.match(/boilerplate/)) continue - if (package0.name.match(packageJson.name)) continue + // Copy the packages into node_modules: - const target = path.resolve(path.join(basePath, 'tmp_packages_for_build', package0.name)) - log(` Copying: ${package0.name} to ${target}`) + const copiedFolders = [] + let ps = [] + for (const package0 of packages) { + if (package0.name.match(/boilerplate/)) continue + if (package0.name.match(packageJson.name)) continue - // log(` ${package0.location} -> ${target}`) - ps.push(fseCopy(package0.location, target)) + const target = path.resolve(path.join(basePath, 'tmp_packages_for_build', package0.name)) + log(` Copying: ${package0.name} to ${target}`) - copiedFolders.push(target) + // log(` ${package0.location} -> ${target}`) + ps.push(fseCopy(package0.location, target)) + + copiedFolders.push(target) + } + + await Promise.all(ps) + ps = [] } - await Promise.all(ps) - ps = [] + // Hack to make pkg include the native dependency @parcel/watcher: + { + log(`Hacking @parcel/watcher...`) + + /* + This hack exploits the line @parcel/watcher/index.js:21 : + binding = require('./build/Release/watcher.node'); + By copying the native module into that location, pkg will include it in the build. + */ + const arch = os.arch() + const platform = os.platform() + const prebuildType = process.argv[2] || `${platform}-${arch}` + + const source = path.join(basePath, `node_modules/@parcel/watcher-${prebuildType}`) // @parcel/watcher-win32-x64 + const target = path.join(basePath, 'node_modules/@parcel/watcher/build/Release') + + log(` Copying: ${source} to ${target}`) + await fse.copy(source, target) + } log(`...done!`) })().catch(log) diff --git a/scripts/reset.js b/scripts/reset.js index 7c0a4cc6..5ff0d0df 100644 --- a/scripts/reset.js +++ b/scripts/reset.js @@ -7,7 +7,7 @@ const rimraf = promisify(require('rimraf')) Removing all /node_modules and /dist folders */ -const basePath = process.cwd() +const basePath = '.' ;(async () => { log('Gathering files to remove...') diff --git a/shared/packages/expectationManager/src/internalManager/internalManager.ts b/shared/packages/expectationManager/src/internalManager/internalManager.ts index 94a44ac0..4270f49b 100644 --- a/shared/packages/expectationManager/src/internalManager/internalManager.ts +++ b/shared/packages/expectationManager/src/internalManager/internalManager.ts @@ -18,7 +18,7 @@ import { WorkerAgentAPI } from '../workerAgentApi' import { getDefaultConstants } from '../lib/constants' import { ExpectationTracker } from '../expectationTracker/expectationTracker' import { TrackedWorkerAgents } from './lib/trackedWorkerAgents' -import { ManagerStatusMonitor } from './lib/managerStatusMonitor' +import { ManagerStatusWatchdog } from './lib/managerStatusWatchdog' import { ExpectationManagerCallbacks, ExpectationManagerOptions, @@ -43,7 +43,7 @@ export class InternalManager { public statuses: ManagerStatusReporter private enableChaosMonkey = false - private managerMonitor: ManagerStatusMonitor + private managerWatchdog: ManagerStatusWatchdog public statusReport: StatusReportCache @@ -79,7 +79,7 @@ export class InternalManager { this.tracker.on('error', (err) => this.logger.error(`ExpectationTracker error" ${stringifyError(err)}`)) this.workerAgents = new TrackedWorkerAgents(this.logger, this.tracker) this.statuses = new ManagerStatusReporter(this.callbacks) - this.managerMonitor = new ManagerStatusMonitor(this.logger, this.tracker, this.statuses) + this.managerWatchdog = new ManagerStatusWatchdog(this.logger, this.tracker, this.statuses) this.statusReport = new StatusReportCache(this) this.enableChaosMonkey = options?.chaosMonkey ?? false @@ -107,7 +107,7 @@ export class InternalManager { this.tracker.terminate() this.expectationManagerServer.terminate() this.workforceConnection.terminate() - this.managerMonitor.terminate() + this.managerWatchdog.terminate() } /** USED IN TESTS ONLY. Quickly reset the tracked work of the expectationManager. */ resetWork(): void { diff --git a/shared/packages/expectationManager/src/internalManager/lib/managerStatusMonitor.ts b/shared/packages/expectationManager/src/internalManager/lib/managerStatusWatchdog.ts similarity index 70% rename from shared/packages/expectationManager/src/internalManager/lib/managerStatusMonitor.ts rename to shared/packages/expectationManager/src/internalManager/lib/managerStatusWatchdog.ts index 647b7a05..5e80f345 100644 --- a/shared/packages/expectationManager/src/internalManager/lib/managerStatusMonitor.ts +++ b/shared/packages/expectationManager/src/internalManager/lib/managerStatusWatchdog.ts @@ -3,11 +3,11 @@ import { ExpectationTracker } from '../../expectationTracker/expectationTracker' import { ManagerStatusReporter } from './managerStatusReporter' /** Monitors the status of the ExpectationTracker and alerts if there's a problem */ -export class ManagerStatusMonitor { - private statusMonitorInterval: NodeJS.Timeout | null = null +export class ManagerStatusWatchdog { + private checkStatusInterval: NodeJS.Timeout | null = null /** Timestamp, used to determine how long the work-queue has been stuck */ - private monitorStatusWaiting: number | null = null + private stuckTimestamp: number | null = null private logger: LoggerInstance constructor( @@ -17,32 +17,32 @@ export class ManagerStatusMonitor { ) { this.logger = logger.category('StatusMonitor') - this.statusMonitorInterval = setInterval(() => { - this._monitorStatus() + this.checkStatusInterval = setInterval(() => { + this._checkStatus() }, 60 * 1000) } public terminate(): void { - if (this.statusMonitorInterval) { - clearInterval(this.statusMonitorInterval) - this.statusMonitorInterval = null + if (this.checkStatusInterval) { + clearInterval(this.checkStatusInterval) + this.checkStatusInterval = null } } - private _monitorStatus() { + private _checkStatus() { // If the work-queue is long (>10 items) and nothing has progressed for the past 10 minutes. const waitingExpectationCount = this.tracker.scaler.getWaitingExpectationCount() if (waitingExpectationCount > 10) { - if (!this.monitorStatusWaiting) { - this.monitorStatusWaiting = Date.now() + if (!this.stuckTimestamp) { + this.stuckTimestamp = Date.now() } } else { - this.monitorStatusWaiting = null + this.stuckTimestamp = null } - const stuckDuration: number = this.monitorStatusWaiting ? Date.now() - this.monitorStatusWaiting : 0 + const stuckDuration: number = this.stuckTimestamp ? Date.now() - this.stuckTimestamp : 0 if (stuckDuration > 10 * 60 * 1000) { this.logger.error(`_monitorStatus: Work Queue is Stuck for ${stuckDuration / 1000 / 60} minutes`) this.managerStatuses.update('work-queue-stuck', { diff --git a/tests/internal-tests/src/__tests__/lib/setupEnv.ts b/tests/internal-tests/src/__tests__/lib/setupEnv.ts index 93a2b9aa..e901a756 100644 --- a/tests/internal-tests/src/__tests__/lib/setupEnv.ts +++ b/tests/internal-tests/src/__tests__/lib/setupEnv.ts @@ -46,6 +46,7 @@ const defaultTestConfig: SingleAppConfig = { logPath: '', unsafeSSL: false, certificates: [], + logLevel: LogLevel.INFO, }, workforce: { port: null, @@ -202,6 +203,7 @@ export async function prepareTestEnviromnent(debugLogging: boolean): Promise