Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
this.onEventHandler = props.onEventHandler;
this.isCompleteHandler = props.isCompleteHandler;
const onEventFunction = this.createFunction(consts.FRAMEWORK_ON_EVENT_HANDLER_NAME);
if (this.isCompleteHandler) {
const isCompleteFunction = this.createFunction(consts.FRAMEWORK_IS_COMPLETE_HANDLER_NAME);
const timeoutFunction = this.createFunction(consts.FRAMEWORK_ON_TIMEOUT_HANDLER_NAME);
const isCompleteTask = this.createTask(isCompleteFunction);
isCompleteTask.addCatch(this.createTask(timeoutFunction));
isCompleteTask.addRetry(calculateRetryPolicy(props));
const waiterStateMachine = new sfn.StateMachine(this, 'waiter-state-machine', {
definition: isCompleteTask
});
// the on-event entrypoint is going to start the execution of the waiter
onEventFunction.addEnvironment(consts.WAITER_STATE_MACHINE_ARN_ENV, waiterStateMachine.stateMachineArn);
waiterStateMachine.grantStartExecution(onEventFunction);
}
this.entrypoint = onEventFunction;
}
lambdaFunction: reviewer,
})
)
)
.next(
new sfn.Choice(scope, "Job Complete?")
.when(condFailed, invokeErrorHandler)
.when(
sfn.Condition.stringEquals("$.status", "SUCCEEDED"),
new tasks.LambdaInvoke(scope, "invokePublishReport", {
lambdaFunction: publishReport,
})
)
);
return new sfn.StateMachine(scope, "InspectionMachine", {
definition,
role: sfnRole,
});
}
const invokeErrorHandler = new tasks.LambdaInvoke(
scope,
"InvokeErrorHandler",
{ lambdaFunction: errorHandler }
);
const definition = wait
.next(invokeDispatcher)
.next(
new sfn.Choice(scope, "Job Complete?").when(
sfn.Condition.stringEquals("$.status", "FAILED"),
invokeErrorHandler
)
);
return new sfn.StateMachine(scope, "InspectionMachine", {
definition,
role: sfnRole,
});
}