import { System } from 'common' ; import { DotenvConfigOutput } from 'dotenv' ; import { Container } from 'inversify' ; import { BaseTelemetryProperties , GlobalLogger , loggerTypes } from 'logger' ; export abstract class ProcessEntryPointBase { constructor ( private readonly container ) { } public async start ( ... args ) { let loggerInitialized = false ; let logger ; try { const dotEnvConfig = this . container . get ( loggerTypes . DotEnvConfig ) ; logger = this . container . get ( GlobalLogger ) ; await logger . setup ( this . getTelemetryBaseProperties ( ) ) ; loggerInitialized = true ; this . verifyDotEnvParsing ( dotEnvConfig , logger ) ; await this . runCustomAction ( this . container , ... args ) ; } catch ( error ) { if ( loggerInitialized === true ) { logger . logError ( 'Error occurred while executing main process.' , { error : System . serializeError ( error ) } ) ; } else { console . log ( 'Error occurred while executing main process.' , { error : System . serializeError ( error ) } ) ; } throw error ; } finally { if ( loggerInitialized === true ) { logger . logInfo ( 'Flushing telemetry events.' ) ; await logger . flush ( ) ; } } } protected abstract getTelemetryBaseProperties ( ) ; protected abstract runCustomAction ( container , ... args ) ; private verifyDotEnvParsing ( dotEnvConfig , logger ) { if ( dotEnvConfig . parsed !== undefined ) { logger . logInfo ( `Loaded environment variables from the .env config file.\n${ JSON . stringify ( dotEnvConfig . parsed , undefined , 2 ) }` ) ; } if ( dotEnvConfig . error !== undefined ) { logger . logWarn ( `Unable to load the .env config file. ${ dotEnvConfig . error }` ) ; } } }