@@ -9,7 +9,13 @@ import * as fs from 'fs'
9
9
import * as os from 'os'
10
10
import { getLogger } from '../../shared/logger'
11
11
import * as CodeWhispererConstants from '../models/constants'
12
- import { transformByQState , StepProgress , TransformByQReviewStatus , JDKVersion } from '../models/model'
12
+ import {
13
+ transformByQState ,
14
+ StepProgress ,
15
+ TransformByQReviewStatus ,
16
+ JDKVersion ,
17
+ sessionPlanProgress ,
18
+ } from '../models/model'
13
19
import { convertToTimeString , convertDateToTimestamp } from '../../shared/utilities/textUtilities'
14
20
import {
15
21
throwIfCancelled ,
@@ -55,18 +61,6 @@ export const stopTransformByQButton = localize('aws.codewhisperer.stop.transform
55
61
56
62
let sessionJobHistory : { timestamp : string ; module : string ; status : string ; duration : string ; id : string } [ ] = [ ]
57
63
58
- const sessionPlanProgress : {
59
- uploadCode : StepProgress
60
- buildCode : StepProgress
61
- transformCode : StepProgress
62
- returnCode : StepProgress
63
- } = {
64
- uploadCode : StepProgress . NotStarted ,
65
- buildCode : StepProgress . NotStarted ,
66
- transformCode : StepProgress . NotStarted ,
67
- returnCode : StepProgress . NotStarted ,
68
- }
69
-
70
64
export async function startTransformByQWithProgress ( ) {
71
65
await startTransformByQ ( )
72
66
}
@@ -158,7 +152,7 @@ export async function startTransformByQ() {
158
152
'aws.amazonq.showPlanProgressInHub' ,
159
153
codeTransformTelemetryState . getStartTime ( )
160
154
)
161
- } , CodeWhispererConstants . progressIntervalMs )
155
+ } , CodeWhispererConstants . transformationJobPollingIntervalSeconds * 1000 )
162
156
163
157
// step 1: CreateCodeUploadUrl and upload code
164
158
const uploadId = await preTransformationUploadCode ( )
@@ -173,6 +167,7 @@ export async function startTransformByQ() {
173
167
const status = await pollTransformationStatusUntilComplete ( jobId )
174
168
175
169
// Set the result state variables for our store and the UI
170
+ // At this point job should be completed or partially completed
176
171
await finalizeTransformationJob ( status )
177
172
} catch ( error : any ) {
178
173
await transformationJobErrorHandler ( error )
@@ -204,7 +199,6 @@ export async function preTransformationUploadCode() {
204
199
} )
205
200
throw err
206
201
}
207
- sessionPlanProgress [ 'uploadCode' ] = StepProgress . Succeeded
208
202
209
203
await sleep ( 2000 ) // sleep before starting job to prevent ThrottlingException
210
204
throwIfCancelled ( )
@@ -238,7 +232,7 @@ export async function startTransformationJob(uploadId: string) {
238
232
239
233
export async function pollTransformationStatusUntilPlanReady ( jobId : string ) {
240
234
try {
241
- await pollTransformationJob ( jobId , CodeWhispererConstants . validStatesForGettingPlan )
235
+ await pollTransformationJob ( jobId , CodeWhispererConstants . validStatesForPlanGenerated )
242
236
} catch ( error ) {
243
237
const errorMessage = CodeWhispererConstants . failedToCompleteJobMessage
244
238
getLogger ( ) . error ( `CodeTransformation: ${ errorMessage } ` , error )
@@ -254,7 +248,7 @@ export async function pollTransformationStatusUntilPlanReady(jobId: string) {
254
248
transformByQState . setJobFailureErrorMessage ( errorMessage )
255
249
throw new Error ( 'Get plan failed' )
256
250
}
257
- sessionPlanProgress [ 'buildCode' ] = StepProgress . Succeeded
251
+
258
252
const planFilePath = path . join ( os . tmpdir ( ) , 'transformation-plan.md' )
259
253
fs . writeFileSync ( planFilePath , plan )
260
254
await vscode . commands . executeCommand ( 'markdown.showPreview' , vscode . Uri . file ( planFilePath ) )
@@ -286,7 +280,6 @@ export async function finalizeTransformationJob(status: string) {
286
280
throw new Error ( 'Job was not successful nor partially successful' )
287
281
}
288
282
289
- sessionPlanProgress [ 'transformCode' ] = StepProgress . Succeeded
290
283
transformByQState . setToSucceeded ( )
291
284
if ( status === 'PARTIALLY_COMPLETED' ) {
292
285
transformByQState . setToPartiallySucceeded ( )
@@ -298,11 +291,7 @@ export async function finalizeTransformationJob(status: string) {
298
291
await vscode . commands . executeCommand ( 'aws.amazonq.transformationHub.reviewChanges.reveal' )
299
292
await vscode . commands . executeCommand ( 'aws.amazonq.refresh' )
300
293
301
- transformByQState . getChatControllers ( ) ?. transformationFinished . fire ( {
302
- jobStatus : status ,
303
- tabID : ChatSessionManager . Instance . getSession ( ) . tabID ,
304
- } )
305
- sessionPlanProgress [ 'returnCode' ] = StepProgress . Succeeded
294
+ sessionPlanProgress [ 'transformCode' ] = StepProgress . Succeeded
306
295
}
307
296
308
297
export async function getValidCandidateProjects ( ) : Promise < TransformationCandidateProject [ ] > {
@@ -311,11 +300,13 @@ export async function getValidCandidateProjects(): Promise<TransformationCandida
311
300
}
312
301
313
302
export async function setTransformationToRunningState ( ) {
303
+ await setContextVariables ( )
304
+
314
305
transformByQState . setToRunning ( )
315
- sessionPlanProgress [ 'uploadCode ' ] = StepProgress . Pending
306
+ sessionPlanProgress [ 'startJob ' ] = StepProgress . Pending
316
307
sessionPlanProgress [ 'buildCode' ] = StepProgress . Pending
308
+ sessionPlanProgress [ 'generatePlan' ] = StepProgress . Pending
317
309
sessionPlanProgress [ 'transformCode' ] = StepProgress . Pending
318
- sessionPlanProgress [ 'returnCode' ] = StepProgress . Pending
319
310
320
311
codeTransformTelemetryState . setStartTime ( )
321
312
@@ -343,13 +334,14 @@ export async function setTransformationToRunningState() {
343
334
codeTransformTelemetryState . getStartTime ( )
344
335
)
345
336
346
- await setContextVariables ( )
347
-
348
337
await vscode . commands . executeCommand ( 'aws.amazonq.refresh' )
349
338
}
350
339
351
340
export async function postTransformationJob ( ) {
352
- await vscode . commands . executeCommand ( 'setContext' , 'gumby.isTransformAvailable' , true )
341
+ transformByQState . getChatControllers ( ) ?. transformationFinished . fire ( {
342
+ jobStatus : transformByQState . getPolledJobStatus ( ) ,
343
+ tabID : ChatSessionManager . Instance . getSession ( ) . tabID ,
344
+ } )
353
345
const durationInMs = calculateTotalLatency ( codeTransformTelemetryState . getStartTime ( ) )
354
346
const resultStatusMessage = codeTransformTelemetryState . getResultStatus ( )
355
347
@@ -441,18 +433,18 @@ export async function transformationJobErrorHandler(error: any) {
441
433
}
442
434
} )
443
435
}
444
- if ( sessionPlanProgress [ 'uploadCode ' ] !== StepProgress . Succeeded ) {
445
- sessionPlanProgress [ 'uploadCode ' ] = StepProgress . Failed
436
+ if ( sessionPlanProgress [ 'startJob ' ] !== StepProgress . Succeeded ) {
437
+ sessionPlanProgress [ 'startJob ' ] = StepProgress . Failed
446
438
}
447
439
if ( sessionPlanProgress [ 'buildCode' ] !== StepProgress . Succeeded ) {
448
440
sessionPlanProgress [ 'buildCode' ] = StepProgress . Failed
449
441
}
442
+ if ( sessionPlanProgress [ 'generatePlan' ] !== StepProgress . Succeeded ) {
443
+ sessionPlanProgress [ 'generatePlan' ] = StepProgress . Failed
444
+ }
450
445
if ( sessionPlanProgress [ 'transformCode' ] !== StepProgress . Succeeded ) {
451
446
sessionPlanProgress [ 'transformCode' ] = StepProgress . Failed
452
447
}
453
- if ( sessionPlanProgress [ 'returnCode' ] !== StepProgress . Succeeded ) {
454
- sessionPlanProgress [ 'returnCode' ] = StepProgress . Failed
455
- }
456
448
getLogger ( ) . error ( `CodeTransformation: ${ error . message } ` )
457
449
}
458
450
@@ -509,8 +501,8 @@ export async function stopTransformByQ(
509
501
}
510
502
511
503
async function setContextVariables ( ) {
504
+ await vscode . commands . executeCommand ( 'setContext' , 'gumby.wasQCodeTransformationUsed' , true )
512
505
await vscode . commands . executeCommand ( 'setContext' , 'gumby.isStopButtonAvailable' , true )
513
- await vscode . commands . executeCommand ( 'setContext' , 'gumby.isTransformAvailable' , false )
514
506
await vscode . commands . executeCommand ( 'setContext' , 'gumby.isPlanAvailable' , false )
515
507
await vscode . commands . executeCommand ( 'setContext' , 'gumby.isSummaryAvailable' , false )
516
508
await vscode . commands . executeCommand ( 'setContext' , 'gumby.reviewState' , TransformByQReviewStatus . NotStarted )
0 commit comments