@@ -20,34 +20,37 @@ function runBuild() {
2020 // get a codeBuild instance from the SDK
2121 const sdk = buildSdk ( ) ;
2222
23+ const inputs = githubInputs ( ) ;
24+
25+ const config = ( ( { updateInterval, updateBackOff } ) => ( {
26+ updateInterval,
27+ updateBackOff,
28+ } ) ) ( inputs ) ;
29+
2330 // Get input options for startBuild
24- const params = inputs2Parameters ( githubInputs ( ) ) ;
31+ const params = inputs2Parameters ( inputs ) ;
2532
26- return build ( sdk , params ) ;
33+ return build ( sdk , params , config ) ;
2734}
2835
29- async function build ( sdk , params ) {
36+ async function build ( sdk , params , config ) {
3037 // Start the build
3138 const start = await sdk . codeBuild . startBuild ( params ) . promise ( ) ;
3239
3340 // Wait for the build to "complete"
34- return waitForBuildEndTime ( sdk , start . build ) ;
41+ return waitForBuildEndTime ( sdk , start . build , config ) ;
3542}
3643
3744async function waitForBuildEndTime (
3845 sdk ,
3946 { id, logs } ,
47+ { updateInterval, updateBackOff } ,
4048 seqEmptyLogs ,
4149 totalEvents ,
4250 throttleCount ,
4351 nextToken
4452) {
45- const {
46- codeBuild,
47- cloudWatchLogs,
48- wait = 1000 * 30 ,
49- backOff = 1000 * 15 ,
50- } = sdk ;
53+ const { codeBuild, cloudWatchLogs } = sdk ;
5154
5255 totalEvents = totalEvents || 0 ;
5356 seqEmptyLogs = seqEmptyLogs || 0 ;
@@ -86,17 +89,21 @@ async function waitForBuildEndTime(
8689 if ( errObject ) {
8790 //We caught an error in trying to make the AWS api call, and are now checking to see if it was just a rate limiting error
8891 if ( errObject . message && errObject . message . search ( "Rate exceeded" ) !== - 1 ) {
89- //We were rate-limited, so add `backOff` seconds to the wait time
90- let newWait = wait + backOff ;
92+ // We were rate-limited, so add backoff with Full Jitter, ref: https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
93+ let jitteredBackOff = Math . floor (
94+ Math . random ( ) * ( updateBackOff * 2 ** throttleCount )
95+ ) ;
96+ let newWait = updateInterval + jitteredBackOff ;
9197 throttleCount ++ ;
9298
9399 //Sleep before trying again
94100 await new Promise ( ( resolve ) => setTimeout ( resolve , newWait ) ) ;
95101
96102 // Try again from the same token position
97103 return waitForBuildEndTime (
98- { ...sdk , wait : newWait } ,
104+ { ...sdk } ,
99105 { id, logs } ,
106+ { updateInterval : newWait , updateBackOff } ,
100107 seqEmptyLogs ,
101108 totalEvents ,
102109 throttleCount ,
@@ -136,13 +143,19 @@ async function waitForBuildEndTime(
136143 // More to do: Sleep for a few seconds to avoid rate limiting
137144 // If never throttled and build is complete, halve CWL polling delay to minimize latency
138145 await new Promise ( ( resolve ) =>
139- setTimeout ( resolve , current . endTime && throttleCount == 0 ? wait / 2 : wait )
146+ setTimeout (
147+ resolve ,
148+ current . endTime && throttleCount == 0
149+ ? updateInterval / 2
150+ : updateInterval
151+ )
140152 ) ;
141153
142154 // Try again
143155 return waitForBuildEndTime (
144156 sdk ,
145157 current ,
158+ { updateInterval, updateBackOff } ,
146159 seqEmptyLogs ,
147160 totalEvents ,
148161 throttleCount ,
@@ -184,6 +197,17 @@ function githubInputs() {
184197 . map ( ( i ) => i . trim ( ) )
185198 . filter ( ( i ) => i !== "" ) ;
186199
200+ const updateInterval =
201+ parseInt (
202+ core . getInput ( "update-interval" , { required : false } ) || "30" ,
203+ 10
204+ ) * 1000 ;
205+ const updateBackOff =
206+ parseInt (
207+ core . getInput ( "update-back-off" , { required : false } ) || "15" ,
208+ 10
209+ ) * 1000 ;
210+
187211 return {
188212 projectName,
189213 owner,
@@ -194,6 +218,8 @@ function githubInputs() {
194218 environmentTypeOverride,
195219 imageOverride,
196220 envPassthrough,
221+ updateInterval,
222+ updateBackOff,
197223 } ;
198224}
199225
0 commit comments