@@ -17,7 +17,6 @@ import {
1717 PackageContainerExpectation ,
1818 Reason ,
1919 stringifyError ,
20- setLogLevel ,
2120 isNodeRunningInDebugMode ,
2221 INNER_ACTION_TIMEOUT ,
2322 DataStore ,
@@ -33,9 +32,10 @@ import {
3332 DataId ,
3433 LockId ,
3534 protectString ,
36- getLogLevel ,
3735 Cost ,
3836 LeveledLogMethodLight ,
37+ isRunningInDevelopment ,
38+ isRunningInTest ,
3939} from '@sofie-package-manager/api'
4040
4141import { WorkforceAPI } from './workforceApi'
@@ -283,9 +283,9 @@ export class AppContainer {
283283
284284 private async discoverAvailableApps ( ) {
285285 const getWorkerArgs = ( appId : AppId , pickUpCriticalExpectationsOnly : boolean ) : string [ ] => {
286- return [
286+ const args : string [ ] = [
287287 // Set initial loglevel to be same as appContainer:
288- `--logLevel=${ getLogLevel ( ) } ` ,
288+ `--logLevel=${ this . logger . getLogLevel ( ) } ` ,
289289
290290 `--workerId=${ appId } ` ,
291291 pickUpCriticalExpectationsOnly ? `--pickUpCriticalExpectationsOnly=true` : '' ,
@@ -296,38 +296,54 @@ export class AppContainer {
296296 this . config . process . certificates . length
297297 ? `--certificates=${ this . config . process . certificates . join ( ';' ) } `
298298 : '' ,
299-
300- this . config . appContainer . worker . windowsDriveLetters
301- ? `--windowsDriveLetters=${ this . config . appContainer . worker . windowsDriveLetters ?. join ( ';' ) } `
302- : '' ,
303- this . config . appContainer . worker . temporaryFolderPath
304- ? `--temporaryFolderPath=${ this . config . appContainer . worker . temporaryFolderPath } `
305- : '' ,
306- this . config . appContainer . worker . costMultiplier
307- ? `--costMultiplier=${ this . config . appContainer . worker . costMultiplier } `
308- : '' ,
309- this . config . appContainer . worker . considerCPULoad
310- ? `--considerCPULoad=${ this . config . appContainer . worker . considerCPULoad } `
311- : '' ,
312- this . config . appContainer . worker . resourceId
313- ? `--resourceId=${ this . config . appContainer . worker . resourceId } `
314- : '' ,
315- this . config . appContainer . worker . networkIds . length
316- ? `--networkIds=${ this . config . appContainer . worker . networkIds . join ( ';' ) } `
317- : '' ,
318- this . config . appContainer . worker . failurePeriodLimit
319- ? `--failurePeriodLimit=${ this . config . appContainer . worker . failurePeriodLimit } `
320- : '' ,
321- this . config . appContainer . worker . failurePeriod
322- ? `--failurePeriod=${ this . config . appContainer . worker . failurePeriod } `
323- : '' ,
324299 ]
300+
301+ const workerArgs = this . config . appContainer . worker
302+ const keys = Object . keys ( workerArgs ) as ( keyof AppContainerProcessConfig [ 'appContainer' ] [ 'worker' ] ) [ ]
303+ for ( const key of keys ) {
304+ let argValue : string | undefined = undefined
305+ if ( key === 'windowsDriveLetters' ) {
306+ argValue = workerArgs . windowsDriveLetters ?. join ( ';' )
307+ } else if ( key === 'temporaryFolderPath' ) {
308+ argValue = workerArgs . temporaryFolderPath
309+ } else if ( key === 'costMultiplier' ) {
310+ argValue = workerArgs . costMultiplier ?. toString ( )
311+ } else if ( key === 'considerCPULoad' ) {
312+ argValue = workerArgs . considerCPULoad ?. toString ( )
313+ } else if ( key === 'resourceId' ) {
314+ argValue = workerArgs . resourceId
315+ } else if ( key === 'networkIds' ) {
316+ argValue = workerArgs . networkIds . join ( ';' )
317+ } else if ( key === 'failurePeriodLimit' ) {
318+ argValue = workerArgs . failurePeriodLimit ?. toString ( )
319+ } else if ( key === 'failurePeriod' ) {
320+ argValue = workerArgs . failurePeriod ?. toString ( )
321+ } else if ( key === 'sourcePackageStabilityThreshold' ) {
322+ argValue = workerArgs . sourcePackageStabilityThreshold ?. toString ( )
323+ } else if ( key === 'executableAliases' ) {
324+ argValue = workerArgs . executableAliases
325+ ? Object . entries < string > ( workerArgs . executableAliases )
326+ . map ( ( [ k , v ] ) => `${ k } =${ v } ` )
327+ . join ( ';' )
328+ : undefined
329+ } else if ( key === 'allowedExpectationTypes' ) {
330+ argValue = workerArgs . allowedExpectationTypes
331+ ? workerArgs . allowedExpectationTypes . join ( ';' )
332+ : undefined
333+ } else if ( key === 'matchFilenamesWithoutExtension' ) {
334+ // This is handled separately above, skip it here
335+ } else {
336+ assertNever ( key )
337+ this . logger . error ( `Unknown worker argument key: "${ key } "=${ workerArgs [ key ] } ` )
338+ }
339+
340+ if ( argValue ) args . push ( `--${ key } =${ argValue } ` )
341+ }
342+
343+ return args
325344 }
326- if (
327- path . basename ( process . execPath ) === 'node.exe' || // windows
328- path . basename ( process . execPath ) === 'node' // linux
329- ) {
330- // Process runs as a node process, we're probably in development mode.
345+
346+ if ( isRunningInDevelopment ( ) || isRunningInTest ( ) ) {
331347 const appType = protectString < AppType > ( 'worker' )
332348 this . availableApps . set ( appType , {
333349 file : process . execPath ,
@@ -381,7 +397,7 @@ export class AppContainer {
381397 }
382398 async setLogLevel ( logLevel : LogLevel ) : Promise < void > {
383399 this . logger . info ( `Setting log level to "${ logLevel } "` )
384- setLogLevel ( logLevel )
400+ this . logger . setLogLevel ( logLevel )
385401 }
386402 async _debugKill ( ) : Promise < void > {
387403 // This is for testing purposes only
@@ -414,7 +430,11 @@ export class AppContainer {
414430 if ( this . availableApps . size === 0 ) {
415431 this . logger . error ( 'No apps available' )
416432 } else {
417- this . logger . debug ( `Available apps: ${ Array . from ( this . availableApps . keys ( ) ) . join ( ', ' ) } ` )
433+ this . logger . debug (
434+ `Available apps: ${ Array . from ( this . availableApps . entries ( ) )
435+ . map ( ( [ key , app ] ) => `${ key } :${ app . file } ` )
436+ . join ( ', ' ) } `
437+ )
418438 }
419439
420440 let lastNotSupportReason : ExpectedPackageStatusAPI . Reason = {
@@ -470,7 +490,11 @@ export class AppContainer {
470490 if ( this . availableApps . size === 0 ) {
471491 this . logger . error ( 'No apps available' )
472492 } else {
473- this . logger . debug ( `Available apps: ${ Array . from ( this . availableApps . keys ( ) ) . join ( ', ' ) } ` )
493+ this . logger . debug (
494+ `Available apps: ${ Array . from ( this . availableApps . entries ( ) )
495+ . map ( ( [ key , app ] ) => `${ key } :${ app . file } ` )
496+ . join ( ', ' ) } `
497+ )
474498 }
475499
476500 for ( const [ appType , availableApp ] of this . availableApps . entries ( ) ) {
@@ -633,10 +657,7 @@ export class AppContainer {
633657 availableApp : AvailableAppInfo ,
634658 useCriticalOnlyMode : boolean
635659 ) : cp . ChildProcess {
636- const isRunningInDevelopmentMode = process . execPath . endsWith ( 'node.exe' ) || process . execPath . endsWith ( 'node' )
637- const cwd = isRunningInDevelopmentMode
638- ? undefined // Process runs as a node process, we're probably in development mode.
639- : path . dirname ( process . execPath ) // Process runs as a node process, we're probably in development mode.
660+ const cwd = isRunningInDevelopment ( ) ? undefined : path . dirname ( process . execPath )
640661
641662 let inspectPort : number | undefined = undefined
642663 if ( isNodeRunningInDebugMode ( ) ) {
0 commit comments