@@ -17,6 +17,21 @@ interface LambdaPerfStackProps extends cdk.StackProps {
1717}
1818
1919export class LambdaPerfStack extends Stack {
20+
21+ attachCronScheduleIfNeeded = ( env : string , hour : number , lambdaFunction : lambda . Function , ruleName : string ) => {
22+ if ( env === 'production' ) {
23+ const rule = new events . Rule ( this , ruleName , {
24+ schedule : events . Schedule . cron ( {
25+ minute : '0' ,
26+ hour : hour . toString ( ) ,
27+ day : '*' ,
28+ month : '*' ,
29+ } )
30+ } ) ;
31+ rule . addTarget ( new targets . LambdaFunction ( lambdaFunction ) ) ;
32+ }
33+ }
34+
2035 constructor ( scope : Construct , id : string , props : LambdaPerfStackProps ) {
2136 super ( scope , id , props ) ;
2237
@@ -75,13 +90,7 @@ export class LambdaPerfStack extends Stack {
7590 role : iam . Role . fromRoleArn ( this , 'RoleFunctionTriggerDeployerRs' , lambdaRoleArn ) ,
7691 } ) ;
7792
78-
79- if ( props . lambdaPerfEnv === 'production' ) {
80- new events . Rule ( this , 'FunctionTriggerDeployerSchedule' , {
81- schedule : events . Schedule . cron ( { minute : '0' , hour : '11' , day : '*' , month : '*' , year : '*' } ) ,
82- targets : [ new targets . LambdaFunction ( functionTriggerDeployerRs ) ] ,
83- } ) ;
84- }
93+ this . attachCronScheduleIfNeeded ( props . lambdaPerfEnv , 11 , functionTriggerDeployerRs , 'FunctionTriggerDeployerSchedule' ) ;
8594
8695 const functionDeployerRs = new lambda . Function ( this , 'FunctionDeployerRs' , {
8796 runtime : lambda . Runtime . PROVIDED_AL2023 ,
@@ -138,7 +147,7 @@ export class LambdaPerfStack extends Stack {
138147 handler : 'bootstrap' ,
139148 code : lambda . Code . fromAsset ( '../target/lambda/function-invoker-rs/bootstrap-function-invoker-rs.zip' ) ,
140149 environment : {
141- ACCOUNT_ID : cdk . Aws . ACCOUNT_ID ,
150+ ACCOUNT_ID : cdk . Aws . ACCOUNT_ID ,
142151 ROLE_ARN : lambdaRoleArn ,
143152 } ,
144153 timeout : cdk . Duration . seconds ( 900 ) ,
@@ -150,32 +159,21 @@ export class LambdaPerfStack extends Stack {
150159 functionInvokerRs . addEventSource (
151160 new lambdaEventSources . SqsEventSource ( invokerQueue , {
152161 batchSize : 3 ,
153- maxBatchingWindow : cdk . Duration . seconds ( 30 ) ,
162+ maxBatchingWindow : cdk . Duration . seconds ( 30 ) ,
154163 } )
155164 ) ;
156165
157166 const resultBuilder = new lambda . Function ( this , 'ResultBuilder' , {
158167 runtime : lambda . Runtime . NODEJS_22_X ,
159168 handler : 'app.handler' ,
160- code : lambda . Code . fromAsset ( '../result-builder' ) ,
169+ code : lambda . Code . fromAsset ( '../result-builder' ) ,
161170 environment : {
162- GH_AUTH_TOKEN : props . githubAuthToken ,
163- LAMBDA_PERF_ENV : props . lambdaPerfEnv ,
171+ GH_AUTH_TOKEN : props . githubAuthToken ,
172+ LAMBDA_PERF_ENV : props . lambdaPerfEnv ,
164173 } ,
165174 timeout : cdk . Duration . seconds ( 60 ) ,
166175 role : iam . Role . fromRoleArn ( this , 'RoleFunctionResultBuilder' , lambdaRoleArn ) ,
167176 } ) ;
168-
169- const rule = new events . Rule ( this , 'ScheduleRule' , {
170- schedule : events . Schedule . cron ( {
171- minute : '0' ,
172- hour : '14' ,
173- day : '*' ,
174- month : '*' ,
175- } )
176- } ) ;
177-
178- // Add the Lambda function as a target for the scheduled rule
179- rule . addTarget ( new targets . LambdaFunction ( resultBuilder ) ) ;
177+ this . attachCronScheduleIfNeeded ( props . lambdaPerfEnv , 14 , resultBuilder , 'ScheduleRule' ) ;
180178 }
181179}
0 commit comments