Skip to content

Commit

Permalink
Merge fix/silent-ffmpeg into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	apps/package-manager/packages/generic/src/packageManager.ts
  • Loading branch information
nytamin committed Oct 12, 2023
2 parents 39ced7f + 7d546d9 commit 35bce1f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
20 changes: 5 additions & 15 deletions apps/package-manager/packages/generic/src/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ 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
private _observers: Array<any> = []

public expectationManager: ExpectationManager

private expectedPackageCache: Map<ExpectedPackageId, ExpectedPackageWrap> = new Map()
public packageContainersCache: PackageContainers = {}

private externalData: { packageContainers: PackageContainers; expectedPackages: ExpectedPackageWrap[] } = {
Expand Down Expand Up @@ -228,6 +228,8 @@ export class PackageManagerHandler {
this._triggerUpdatedExpectedPackagesTimeout = setTimeout(() => {
this._triggerUpdatedExpectedPackagesTimeout = null

const timer = startTimer()

const packageContainers: PackageContainers = {}
const expectedPackageSources: {
sourceName: string
Expand Down Expand Up @@ -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)
}

Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions scripts/build-win32.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion scripts/cleanup-after-build32.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { promisify } from 'util'

const glob = promisify(glob0)

const basePath = process.cwd()
const basePath = '.'

console.log(`Cleaning up...`)

Expand All @@ -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 }))
Expand Down
69 changes: 47 additions & 22 deletions scripts/prepare-for-build32.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion scripts/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,7 +43,7 @@ export class InternalManager {
public statuses: ManagerStatusReporter

private enableChaosMonkey = false
private managerMonitor: ManagerStatusMonitor
private managerWatchdog: ManagerStatusWatchdog

public statusReport: StatusReportCache

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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', {
Expand Down
2 changes: 2 additions & 0 deletions tests/internal-tests/src/__tests__/lib/setupEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const defaultTestConfig: SingleAppConfig = {
logPath: '',
unsafeSSL: false,
certificates: [],
logLevel: LogLevel.INFO,
},
workforce: {
port: null,
Expand Down Expand Up @@ -202,6 +203,7 @@ export async function prepareTestEnviromnent(debugLogging: boolean): Promise<Tes
certificates: [],
logPath: undefined,
unsafeSSL: false,
logLevel: debugLogging ? LogLevel.DEBUG : LogLevel.INFO,
},
}
initializeLogger(config)
Expand Down

0 comments on commit 35bce1f

Please sign in to comment.