@@ -19,22 +19,26 @@ export const TriggerLocalBuild = async (event: any = {}, context: any = {}): Pro
1919 const consoleLogger = new ConsoleLogger ( ) ;
2020 const sqs = new SQSConnector ( consoleLogger , c ) ;
2121 const body = JSON . parse ( event . body ) ;
22+ let resp = { } ;
2223 try {
2324 consoleLogger . info ( body . jobId , 'enqueuing Job' ) ;
2425 await sqs . sendMessage ( new JobQueueMessage ( body . jobId , JobStatus . inQueue ) , c . get ( 'jobUpdatesQueueUrl' ) , 0 ) ;
2526 consoleLogger . info ( body . jobId , 'Job Queued Job' ) ;
26- return {
27+ resp = {
2728 statusCode : 202 ,
2829 headers : { 'Content-Type' : 'text/plain' } ,
2930 body : body . jobId ,
3031 } ;
3132 } catch ( err ) {
3233 consoleLogger . error ( 'TriggerLocalBuild' , err ) ;
33- return {
34+ resp = {
3435 statusCode : 500 ,
3536 headers : { 'Content-Type' : 'text/plain' } ,
3637 body : err ,
3738 } ;
39+ } finally {
40+ await client . close ( ) ;
41+ return resp ;
3842 }
3943} ;
4044
@@ -108,6 +112,8 @@ export const FailStuckJobs = async () => {
108112 await jobRepository . failStuckJobs ( hours ) ;
109113 } catch ( err ) {
110114 consoleLogger . error ( 'FailStuckJobs' , err ) ;
115+ } finally {
116+ await client . close ( ) ;
111117 }
112118} ;
113119
@@ -126,6 +132,8 @@ async function saveTaskId(jobId: string, taskExecutionRes: any, consoleLogger: C
126132 await jobRepository . addTaskIdToJob ( jobId , taskId ) ;
127133 } catch ( err ) {
128134 consoleLogger . error ( 'saveTaskId' , err ) ;
135+ } finally {
136+ await client . close ( ) ;
129137 }
130138}
131139
@@ -181,6 +189,7 @@ async function NotifyBuildSummary(jobId: string): Promise<any> {
181189 ) ,
182190 entitlement [ 'slack_user_id' ]
183191 ) ;
192+ await client . close ( ) ;
184193 return {
185194 statusCode : 200 ,
186195 } ;
@@ -284,6 +293,7 @@ async function NotifyBuildProgress(jobId: string): Promise<any> {
284293 ) ,
285294 entitlement [ 'slack_user_id' ]
286295 ) ;
296+ await client . close ( ) ;
287297 return {
288298 statusCode : 200 ,
289299 } ;
@@ -333,4 +343,5 @@ async function SubmitArchiveJob(jobId: string) {
333343 repo . prefix [ environment ]
334344 ) ;
335345 consoleLogger . info ( 'submit archive job' , JSON . stringify ( { jobId : jobId , batchJobId : response . jobId } ) ) ;
346+ await client . close ( ) ;
336347}
0 commit comments