Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Silent ffmpeg bug (SOFIE-2650) #102

Merged
merged 18 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class AppContainer {
this.initWorkForceApiPromise = { resolve, reject }
})

this.logger.info(`Initialized"`)
this.logger.info(`Initialized`)
}
/** Return the API-methods that the AppContainer exposes to the WorkerAgent */
private getWorkerAgentAPI(clientId: string): AppContainerWorkerAgent.AppContainer {
Expand Down
2 changes: 1 addition & 1 deletion apps/package-manager/packages/generic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@sofie-package-manager/api": "1.42.1",
"@sofie-package-manager/expectation-manager": "1.42.1",
"@sofie-package-manager/worker": "1.42.1",
"chokidar": "^3.5.1",
"@parcel/watcher": "^2.3.0",
"data-store": "^4.0.3",
"deep-extend": "^0.6.0",
"fast-clone": "^1.5.13",
Expand Down
28 changes: 9 additions & 19 deletions apps/package-manager/packages/generic/src/connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
import { ExpectationManager, ExpectationManagerServerOptions } from '@sofie-package-manager/expectation-manager'
import { CoreHandler, CoreConfig } from './coreHandler'
import { PackageContainers, PackageManagerHandler } from './packageManager'
import chokidar from 'chokidar'
import fs from 'fs'
import { promisify } from 'util'
import path from 'path'
Expand Down Expand Up @@ -213,31 +212,22 @@ export class Connector {
'utf-8'
)
}

const watcher = chokidar.watch(fileName, { persistent: true })

this.logger.info(`Watching file "${fileName}"`)

watcher
.on('add', () => {
triggerReloadInput()
})
.on('change', () => {
triggerReloadInput()
})
.on('unlink', () => {
triggerReloadInput()
})
.on('error', (error) => {
this.logger.error(`Error emitter in Filewatcher: ${stringifyError(error)}`)
})
const triggerReloadInput = () => {
setTimeout(() => {
reloadInput().catch((error) => {
this.logger.error(`Error in reloadInput: ${stringifyError(error)}`)
})
}, 100)
}

this.logger.info(`Watching file "${fileName}"`)
fs.watchFile(fileName, { persistent: true }, (currStats, prevStats) => {
if (currStats.mtimeMs !== prevStats.mtimeMs) {
triggerReloadInput()
}
})
triggerReloadInput()

const reloadInput = async () => {
this.logger.info(`Change detected in ${fileName}`)
// Check that the file exists:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function getPackageContainerExpectations(
packages: {
label: 'Monitor Packages on source',
targetLayers: ['target0'],
ignore: '.bat',
ignore: ['.bat'],
// ignore: '',
},
},
Expand All @@ -43,9 +43,6 @@ export function getPackageContainerExpectations(
packages: {
label: 'Monitor for Smartbull',
targetLayers: ['source-smartbull'], // not used, since the layers of the original smartbull-package are used
usePolling: 2000,
awaitWriteFinishStabilityThreshold: 2000,
warningLimit: 3000, // We seem to get performance issues at around 9000 (when polling network drives), so 3000 should give us an early warning
},
},
}
Expand Down
87 changes: 60 additions & 27 deletions apps/package-manager/packages/generic/src/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export class PackageManagerHandler {

public expectationManager: ExpectationManager

private expectedPackageCache: { [id: string]: ExpectedPackageWrap } = {}
public packageContainersCache: PackageContainers = {}

private externalData: { packageContainers: PackageContainers; expectedPackages: ExpectedPackageWrap[] } = {
Expand All @@ -51,7 +50,9 @@ export class PackageManagerHandler {
}
private _triggerUpdatedExpectedPackagesTimeout: NodeJS.Timeout | null = null
public monitoredPackages: {
[monitorId: string]: ResultingExpectedPackage[]
[containerId: string]: {
[monitorId: string]: ResultingExpectedPackage[]
}
} = {}
settings: PackageManagerSettings = {
delayRemoval: 0,
Expand Down Expand Up @@ -190,8 +191,13 @@ export class PackageManagerHandler {
this._triggerUpdatedExpectedPackagesTimeout = setTimeout(() => {
this._triggerUpdatedExpectedPackagesTimeout = null

const expectedPackages: ExpectedPackageWrap[] = []
const startTime = Date.now()

const packageContainers: PackageContainers = {}
const expectedPackageSources: {
sourceName: string
expectedPackages: ExpectedPackageWrap[]
}[] = []

let activePlaylist: ActivePlaylist = {
_id: '',
Expand All @@ -202,10 +208,17 @@ export class PackageManagerHandler {

// Add from external data:
{
const expectedPackagesExternal: ExpectedPackageWrap[] = []
for (const expectedPackage of this.externalData.expectedPackages) {
expectedPackages.push(expectedPackage)
expectedPackagesExternal.push(expectedPackage)
}
Object.assign(packageContainers, this.externalData.packageContainers)
if (expectedPackagesExternal.length > 0) {
expectedPackageSources.push({
sourceName: 'external',
expectedPackages: expectedPackagesExternal,
})
}
}

if (!this.coreHandler.notUsingCore) {
Expand All @@ -222,6 +235,7 @@ export class PackageManagerHandler {

// Add from Core collections:
{
const expectedPackagesCore: ExpectedPackageWrap[] = []
const expectedPackageObjs = objs.filter((o) => o.type === 'expected_packages')

if (!expectedPackageObjs.length) {
Expand All @@ -232,7 +246,7 @@ export class PackageManagerHandler {
for (const expectedPackageObj of expectedPackageObjs) {
for (const expectedPackage of expectedPackageObj.expectedPackages) {
// Note: There might be duplicates of packages here, to be deduplicated later
expectedPackages.push(expectedPackage)
expectedPackagesCore.push(expectedPackage)
}
}

Expand All @@ -243,19 +257,30 @@ export class PackageManagerHandler {
return
}
Object.assign(packageContainers, packageContainerObj.packageContainers as PackageContainers)
if (expectedPackagesCore.length > 0) {
expectedPackageSources.push({
sourceName: 'core',
expectedPackages: expectedPackagesCore,
})
}
}
}

// Add from Monitors:
{
for (const monitorExpectedPackages of Object.values(this.monitoredPackages)) {
for (const expectedPackage of monitorExpectedPackages) {
expectedPackages.push(expectedPackage)
for (const monitors of Object.values(this.monitoredPackages)) {
for (const [monitorId, monitorExpectedPackages] of Object.entries(monitors)) {
expectedPackageSources.push({
sourceName: `monitor_${monitorId}`,
expectedPackages: monitorExpectedPackages,
})
}
}
}

this.handleExpectedPackages(packageContainers, activePlaylist, activeRundowns, expectedPackages)
this.handleExpectedPackages(packageContainers, activePlaylist, activeRundowns, expectedPackageSources)

this.logger.debug(`Took ${Date.now() - startTime}ms to handle updated expectedPackages`)
}, 300)
}

Expand All @@ -264,24 +289,27 @@ export class PackageManagerHandler {
activePlaylist: ActivePlaylist,
activeRundowns: ActiveRundown[],

expectedPackages: ExpectedPackageWrap[]
expectedPackageSources: {
sourceName: string
expectedPackages: ExpectedPackageWrap[]
}[]
) {
// Step 0: Save local cache:
this.expectedPackageCache = {}
this.packageContainersCache = packageContainers
for (const exp of expectedPackages) {
// Note: There might be duplicates in expectedPackages

const existing = this.expectedPackageCache[exp.expectedPackage._id]
if (
!existing ||
existing.priority > exp.priority // If the existing priority is lower (ie higher), replace it
) {
this.expectedPackageCache[exp.expectedPackage._id] = exp
const expectedPackages: ExpectedPackageWrap[] = []
for (const expectedPackageSource of expectedPackageSources) {
for (const exp of expectedPackageSource.expectedPackages) {
expectedPackages.push(exp)
}
}

this.logger.debug(`Has ${expectedPackages.length} expectedPackages`)
// Step 0: Save local cache:
this.packageContainersCache = packageContainers

this.logger.debug(
`Has ${expectedPackages.length} expectedPackages (${expectedPackageSources
.map((s) => `${s.sourceName}: ${s.expectedPackages.length}`)
.join(', ')})`
)
this.logger.silly(JSON.stringify(expectedPackages, null, 2))
// this.logger.debug(JSON.stringify(expectedPackages, null, 2))

this.dataSnapshot.expectedPackages = expectedPackages
Expand All @@ -298,15 +326,19 @@ export class PackageManagerHandler {
this.settings
)
this.logger.debug(`Has ${Object.keys(expectations).length} expectations`)
this.logger.silly(JSON.stringify(expectations, null, 2))
// this.logger.debug(JSON.stringify(expectations, null, 2))
this.dataSnapshot.expectations = expectations

this.logger.debug(`Has ${Object.keys(this.packageContainersCache).length} packageContainers`)
this.logger.silly(JSON.stringify(this.packageContainersCache, null, 2))
const packageContainerExpectations = this.expectationGeneratorApi.getPackageContainerExpectations(
this.expectationManager.managerId,
this.packageContainersCache,
activePlaylist
)
this.logger.debug(`Has ${Object.keys(packageContainerExpectations).length} packageContainerExpectations`)
this.logger.silly(JSON.stringify(packageContainerExpectations, null, 2))
this.dataSnapshot.packageContainerExpectations = packageContainerExpectations
this.dataSnapshot.updated = Date.now()

Expand Down Expand Up @@ -364,7 +396,7 @@ export class PackageManagerHandler {
return this.expectationManager.debugKillApp(appId)
}

/** Ensures that the packageContainerExpectations containes the mandatory expectations */
/** Ensures that the packageContainerExpectations contains the mandatory expectations */
private ensureMandatoryPackageContainerExpectations(packageContainerExpectations: {
[id: string]: PackageContainerExpectation
}): void {
Expand Down Expand Up @@ -612,7 +644,7 @@ class ExpectationManagerCallbacksHandler implements ExpectationManagerCallbacks
)
}
case 'reportFromMonitorPackages':
this.reportMonitoredPackages(...message.arguments)
this.onReportMonitoredPackages(...message.arguments)
break

default:
Expand Down Expand Up @@ -925,7 +957,7 @@ class ExpectationManagerCallbacksHandler implements ExpectationManagerCallbacks
.catch((e) => this.logger.error(`Error in updateCoreStatus : ${stringifyError(e)}`))
}

private reportMonitoredPackages(_containerId: string, monitorId: string, expectedPackages: ExpectedPackage.Any[]) {
private onReportMonitoredPackages(containerId: string, monitorId: string, expectedPackages: ExpectedPackage.Any[]) {
const expectedPackagesWraps: ExpectedPackageWrap[] = []

for (const expectedPackage of expectedPackages) {
Expand All @@ -939,7 +971,8 @@ class ExpectationManagerCallbacksHandler implements ExpectationManagerCallbacks
`reportMonitoredPackages: ${expectedPackages.length} packages, ${expectedPackagesWraps.length} wraps`
)

this.packageManager.monitoredPackages[monitorId] = expectedPackagesWraps
if (!this.packageManager.monitoredPackages[containerId]) this.packageManager.monitoredPackages[containerId] = {}
this.packageManager.monitoredPackages[containerId][monitorId] = expectedPackagesWraps

this.packageManager.triggerUpdatedExpectedPackages()
}
Expand Down
15 changes: 14 additions & 1 deletion apps/single-app/app/src/singleApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ import * as QuantelHTTPTransformerProxy from '@quantel-http-transformer-proxy/ge
import * as PackageManager from '@package-manager/generic'
import * as Workforce from '@sofie-package-manager/workforce'
import * as AppConatainerNode from '@appcontainer-node/generic'
import { getSingleAppConfig, ProcessHandler, setupLogger, initializeLogger } from '@sofie-package-manager/api'
import {
getSingleAppConfig,
ProcessHandler,
setupLogger,
initializeLogger,
setLogLevel,
isLogLevel,
} from '@sofie-package-manager/api'

export async function startSingleApp(): Promise<void> {
const config = await getSingleAppConfig()
initializeLogger(config)
const logger = setupLogger(config, 'single-app')
const baseLogger = setupLogger(config, '')

const logLevel = config.process.logLevel
if (logLevel && isLogLevel(logLevel)) {
logger.info(`Setting log level to ${logLevel}`)
setLogLevel(logLevel)
}
// Override some of the arguments, as they arent used in the single-app
config.packageManager.port = 0 // 0 = Set the packageManager port to whatever is available
config.packageManager.accessUrl = 'ws:127.0.0.1'
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
Loading
Loading