@@ -20,6 +20,24 @@ fileLogService.logData({ message: "Initializing Cleanup process." });
2020const commandsInfos : ISpawnCommandInfo [ ] = [ ] ;
2121const filesToDelete : string [ ] = [ ] ;
2222const jsCommands : IJSCommand [ ] = [ ] ;
23+ const requests : IRequestInfo [ ] = [ ] ;
24+
25+ const executeRequest = async ( request : IRequestInfo ) => {
26+ const $httpClient = $injector . resolve < Server . IHttpClient > ( "httpClient" ) ;
27+ try {
28+ fileLogService . logData ( { message : `Start executing request: ${ request . method } ${ request . url } ` } ) ;
29+ const response = await $httpClient . httpRequest ( {
30+ url : request . url ,
31+ method : request . method ,
32+ headers : request . headers ,
33+ body : request . body
34+ } ) ;
35+ const responseStatus = response && response . response && response . response . statusCode ;
36+ fileLogService . logData ( { message : `Finished executing request: ${ request . method } ${ request . url } and got status ${ responseStatus } ` } ) ;
37+ } catch ( e ) {
38+ fileLogService . logData ( { message : `Unable to execute request: ${ request . method } ${ request . url } ` } ) ;
39+ }
40+ } ;
2341
2442const executeJSCleanup = async ( jsCommand : IJSCommand ) => {
2543 const $childProcess = $injector . resolve < IChildProcess > ( "childProcess" ) ;
@@ -28,7 +46,7 @@ const executeJSCleanup = async (jsCommand: IJSCommand) => {
2846 fileLogService . logData ( { message : `Start executing action for file: ${ jsCommand . filePath } and data ${ JSON . stringify ( jsCommand . data ) } ` } ) ;
2947
3048 await $childProcess . trySpawnFromCloseEvent ( process . execPath , [ path . join ( __dirname , "cleanup-js-subprocess.js" ) , pathToBootstrap , logFile , jsCommand . filePath , JSON . stringify ( jsCommand . data ) ] , { } , { throwError : true , timeout : jsCommand . timeout || 3000 } ) ;
31- fileLogService . logData ( { message : `Finished xecuting action for file: ${ jsCommand . filePath } and data ${ JSON . stringify ( jsCommand . data ) } ` } ) ;
49+ fileLogService . logData ( { message : `Finished executing action for file: ${ jsCommand . filePath } and data ${ JSON . stringify ( jsCommand . data ) } ` } ) ;
3250
3351 } catch ( err ) {
3452 fileLogService . logData ( { message : `Unable to execute action for file ${ jsCommand . filePath } with data ${ JSON . stringify ( jsCommand . data ) } . Error is: ${ err } .` , type : FileLogMessageType . Error } ) ;
@@ -38,6 +56,10 @@ const executeJSCleanup = async (jsCommand: IJSCommand) => {
3856const executeCleanup = async ( ) => {
3957 const $childProcess = $injector . resolve < IChildProcess > ( "childProcess" ) ;
4058
59+ for ( const request of requests ) {
60+ await executeRequest ( request ) ;
61+ }
62+
4163 for ( const jsCommand of jsCommands ) {
4264 await executeJSCleanup ( jsCommand ) ;
4365 }
@@ -46,7 +68,7 @@ const executeCleanup = async () => {
4668 try {
4769 fileLogService . logData ( { message : `Start executing command: ${ JSON . stringify ( commandInfo ) } ` } ) ;
4870
49- await $childProcess . trySpawnFromCloseEvent ( commandInfo . command , commandInfo . args , { } , { throwError : true , timeout : commandInfo . timeout || 3000 } ) ;
71+ await $childProcess . trySpawnFromCloseEvent ( commandInfo . command , commandInfo . args , commandInfo . options || { } , { throwError : true , timeout : commandInfo . timeout || 3000 } ) ;
5072 fileLogService . logData ( { message : `Successfully executed command: ${ JSON . stringify ( commandInfo ) } ` } ) ;
5173 } catch ( err ) {
5274 fileLogService . logData ( { message : `Unable to execute command: ${ JSON . stringify ( commandInfo ) } . Error is: ${ err } .` , type : FileLogMessageType . Error } ) ;
@@ -84,6 +106,24 @@ const removeCleanupAction = (commandInfo: ISpawnCommandInfo): void => {
84106 }
85107} ;
86108
109+ const addRequest = ( requestInfo : IRequestInfo ) : void => {
110+ if ( _ . some ( requests , currentRequestInfo => _ . isEqual ( currentRequestInfo , requestInfo ) ) ) {
111+ fileLogService . logData ( { message : `cleanup-process will not add request for execution as it has been added already: ${ JSON . stringify ( requestInfo ) } ` } ) ;
112+ } else {
113+ fileLogService . logData ( { message : `cleanup-process added request for execution: ${ JSON . stringify ( requestInfo ) } ` } ) ;
114+ requests . push ( requestInfo ) ;
115+ }
116+ } ;
117+
118+ const removeRequest = ( requestInfo : IRequestInfo ) : void => {
119+ if ( _ . some ( requests , currentRequestInfo => _ . isEqual ( currentRequestInfo , currentRequestInfo ) ) ) {
120+ _ . remove ( requests , currentRequestInfo => _ . isEqual ( currentRequestInfo , requestInfo ) ) ;
121+ fileLogService . logData ( { message : `cleanup-process removed request for execution: ${ JSON . stringify ( requestInfo ) } ` } ) ;
122+ } else {
123+ fileLogService . logData ( { message : `cleanup-process cannot remove request for execution as it has not been added before: ${ JSON . stringify ( requestInfo ) } ` } ) ;
124+ }
125+ } ;
126+
87127const addDeleteAction = ( filePath : string ) : void => {
88128 const fullPath = path . resolve ( filePath ) ;
89129
@@ -142,6 +182,12 @@ process.on("message", async (cleanupProcessMessage: ICleanupMessageBase) => {
142182 case CleanupProcessMessage . RemoveCleanCommand :
143183 removeCleanupAction ( ( < ISpawnCommandCleanupMessage > cleanupProcessMessage ) . commandInfo ) ;
144184 break ;
185+ case CleanupProcessMessage . AddRequest :
186+ addRequest ( ( < IRequestCleanupMessage > cleanupProcessMessage ) . requestInfo ) ;
187+ break ;
188+ case CleanupProcessMessage . RemoveRequest :
189+ removeRequest ( ( < IRequestCleanupMessage > cleanupProcessMessage ) . requestInfo ) ;
190+ break ;
145191 case CleanupProcessMessage . AddDeleteFileAction :
146192 addDeleteAction ( ( < IFileCleanupMessage > cleanupProcessMessage ) . filePath ) ;
147193 break ;
0 commit comments