import { GuidGenerator , ServiceConfiguration } from 'common' ; import { inject , injectable } from 'inversify' ; import { ContextAwareLogger } from 'logger' ; import { WebController } from 'service-library' ; import { FunctionTimer } from '../contracts/function-timer' ; @ injectable ( ) export class HealthMonitorTimerController extends WebController { public readonly apiVersion = '1.0' ; public readonly apiName = 'health-monitor-timer' ; private readonly orchestrationFuncName = 'health-monitor-orchestration-func' ; public constructor ( @ inject ( ServiceConfiguration ) protected readonly serviceConfig , @ inject ( ContextAwareLogger ) logger , @ inject ( GuidGenerator ) private readonly guidGenerator ) { super ( logger ) ; } protected async handleRequest ( ... args ) { const funcTimer = < FunctionTimer > args [ 0 ] ; this . logger . setCommonProperties ( { source : 'healthMonitorTimerFunc' } ) ; this . logger . logInfo ( `Executing '${ this . context . executionContext . functionName }' function.` , { funcName : this . context . executionContext . functionName , invocationId : this . context . executionContext . invocationId , isPastDue : `${ funcTimer . isPastDue . toString ( ) }` , } ) ; const startArgs = [ { FunctionName : this . orchestrationFuncName , InstanceId : this . guidGenerator . createGuid ( ) , } , ] ; this . context . bindings . orchestrationFunc = startArgs ; this . logger . logInfo ( `Started new '${ this . orchestrationFuncName }' orchestration function instance.` ) ; } protected validateRequest ( ... args ) { if ( ( < FunctionTimer > args [ 0 ] ) . isPastDue ) { this . logger . logWarn ( `The '${ this . context . executionContext . functionName }' function trigger is past due.` ) ; } return true ; } }