@@ -20,6 +20,24 @@ fileLogService.logData({ message: "Initializing Cleanup process." });
20
20
const commandsInfos : ISpawnCommandInfo [ ] = [ ] ;
21
21
const filesToDelete : string [ ] = [ ] ;
22
22
const 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
+ } ;
23
41
24
42
const executeJSCleanup = async ( jsCommand : IJSCommand ) => {
25
43
const $childProcess = $injector . resolve < IChildProcess > ( "childProcess" ) ;
@@ -28,7 +46,7 @@ const executeJSCleanup = async (jsCommand: IJSCommand) => {
28
46
fileLogService . logData ( { message : `Start executing action for file: ${ jsCommand . filePath } and data ${ JSON . stringify ( jsCommand . data ) } ` } ) ;
29
47
30
48
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 ) } ` } ) ;
32
50
33
51
} catch ( err ) {
34
52
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) => {
38
56
const executeCleanup = async ( ) => {
39
57
const $childProcess = $injector . resolve < IChildProcess > ( "childProcess" ) ;
40
58
59
+ for ( const request of requests ) {
60
+ await executeRequest ( request ) ;
61
+ }
62
+
41
63
for ( const jsCommand of jsCommands ) {
42
64
await executeJSCleanup ( jsCommand ) ;
43
65
}
@@ -46,7 +68,7 @@ const executeCleanup = async () => {
46
68
try {
47
69
fileLogService . logData ( { message : `Start executing command: ${ JSON . stringify ( commandInfo ) } ` } ) ;
48
70
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 } ) ;
50
72
fileLogService . logData ( { message : `Successfully executed command: ${ JSON . stringify ( commandInfo ) } ` } ) ;
51
73
} catch ( err ) {
52
74
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 => {
84
106
}
85
107
} ;
86
108
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
+
87
127
const addDeleteAction = ( filePath : string ) : void => {
88
128
const fullPath = path . resolve ( filePath ) ;
89
129
@@ -142,6 +182,12 @@ process.on("message", async (cleanupProcessMessage: ICleanupMessageBase) => {
142
182
case CleanupProcessMessage . RemoveCleanCommand :
143
183
removeCleanupAction ( ( < ISpawnCommandCleanupMessage > cleanupProcessMessage ) . commandInfo ) ;
144
184
break ;
185
+ case CleanupProcessMessage . AddRequest :
186
+ addRequest ( ( < IRequestCleanupMessage > cleanupProcessMessage ) . requestInfo ) ;
187
+ break ;
188
+ case CleanupProcessMessage . RemoveRequest :
189
+ removeRequest ( ( < IRequestCleanupMessage > cleanupProcessMessage ) . requestInfo ) ;
190
+ break ;
145
191
case CleanupProcessMessage . AddDeleteFileAction :
146
192
addDeleteAction ( ( < IFileCleanupMessage > cleanupProcessMessage ) . filePath ) ;
147
193
break ;
0 commit comments