Skip to content

Commit c100000

Browse files
committed
add more messaging during refresh and check for in progress jobs when transform initiated; create unit tests for job history feature
1 parent bd79bc1 commit c100000

File tree

7 files changed

+644
-115
lines changed

7 files changed

+644
-115
lines changed

packages/core/src/amazonqGumby/chat/controller/controller.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
import { getAuthType } from '../../../auth/utils'
5959
import fs from '../../../shared/fs/fs'
6060
import { setContext } from '../../../shared/vscode/setContext'
61+
import { readHistoryFile } from '../../../codewhisperer/service/transformByQ/transformationHubViewProvider'
6162

6263
// These events can be interactions within the chat,
6364
// or elsewhere in the IDE
@@ -189,9 +190,16 @@ export class GumbyController {
189190
}
190191

191192
private async transformInitiated(message: any) {
192-
this.messenger.sendViewHistoryMessage(message.tabID)
193+
// check if any jobs potentially still in progress on backend
194+
const history = readHistoryFile()
195+
let numInProgress = 0
196+
history.forEach((job) => {
197+
if (job.status === 'FAILED') {
198+
numInProgress += 1
199+
}
200+
})
201+
this.messenger.sendViewHistoryMessage(message.tabID, numInProgress)
193202
if (transformByQState.isRefreshInProgress()) {
194-
transformByQState.setBlockedByRefresh(true)
195203
this.messenger.sendMessage(
196204
'A job refresh is currently in progress. Please wait for it to complete.',
197205
message.tabID,
@@ -470,7 +478,6 @@ export class GumbyController {
470478

471479
private async handleUserLanguageUpgradeProjectChoice(message: any) {
472480
if (transformByQState.isRefreshInProgress()) {
473-
transformByQState.setBlockedByRefresh(true)
474481
this.messenger.sendMessage(
475482
'A job refresh is currently in progress. Please wait for it to complete.',
476483
message.tabID,
@@ -511,7 +518,6 @@ export class GumbyController {
511518

512519
private async handleUserSQLConversionProjectSelection(message: any) {
513520
if (transformByQState.isRefreshInProgress()) {
514-
transformByQState.setBlockedByRefresh(true)
515521
this.messenger.sendMessage(
516522
'A job refresh is currently in progress. Please wait for it to complete.',
517523
message.tabID,

packages/core/src/amazonqGumby/chat/controller/messenger/messenger.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export class Messenger {
377377
this.dispatcher.sendChatMessage(jobSubmittedMessage)
378378
}
379379

380-
public sendViewHistoryMessage(tabID: string) {
380+
public sendViewHistoryMessage(tabID: string, numInProgress: number) {
381381
const buttons: ChatItemButton[] = []
382382

383383
buttons.push({
@@ -387,9 +387,14 @@ export class Messenger {
387387
disabled: false,
388388
})
389389

390+
const messageText =
391+
numInProgress > 0
392+
? `You have ${numInProgress} job${numInProgress > 1 ? 's' : ''} in progress. You can resume ${numInProgress > 1 ? 'them' : 'it'} in the transformation history table.`
393+
: 'View previous transformations run from the IDE'
394+
390395
const message = new ChatMessage(
391396
{
392-
message: 'View previous transformations run from the IDE',
397+
message: messageText,
393398
messageType: 'ai-prompt',
394399
buttons,
395400
},
@@ -398,6 +403,15 @@ export class Messenger {
398403
this.dispatcher.sendChatMessage(message)
399404
}
400405

406+
public sendJobRefreshInProgressMessage(tabID: string, jobId: string) {
407+
this.dispatcher.sendAsyncEventProgress(
408+
new AsyncEventProgressMessage(tabID, {
409+
inProgress: true,
410+
message: `I am now resuming your job (id: ${jobId}). This can take 10 to 30 minutes to complete.`,
411+
})
412+
)
413+
}
414+
401415
public sendMessage(prompt: string, tabID: string, type: 'prompt' | 'ai-prompt') {
402416
this.dispatcher.sendChatMessage(
403417
new ChatMessage(

packages/core/src/codewhisperer/commands/startTransformByQ.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import { convertDateToTimestamp } from '../../shared/datetime'
7979
import { findStringInDirectory } from '../../shared/utilities/workspaceUtils'
8080
import { makeTemporaryToolkitFolder } from '../../shared/filesystemUtilities'
8181
import { AuthUtil } from '../util/authUtil'
82-
import { updateHistoryTable } from '../service/transformByQ/transformationHubViewProvider'
82+
import { TransformationHubViewProvider } from '../service/transformByQ/transformationHubViewProvider'
8383

8484
export function getFeedbackCommentData() {
8585
const jobId = transformByQState.getJobId()
@@ -803,33 +803,19 @@ export async function postTransformationJob() {
803803

804804
const jobDetails = fields.join('\t') + '\n'
805805
fs.writeFileSync(historyLogFilePath, jobDetails, { flag: 'a' })
806-
await updateHistoryTable(true)
806+
await TransformationHubViewProvider.instance.updateContent('job history', undefined, true)
807807
}
808808
}
809809

810810
export async function transformationJobErrorHandler(error: any) {
811811
if (!transformByQState.isCancelled()) {
812812
// means some other error occurred; cancellation already handled by now with stopTransformByQ
813-
await stopJob(transformByQState.getJobId())
814813
transformByQState.setToFailed()
815814
transformByQState.setPolledJobStatus('FAILED')
816815
// jobFailureErrorNotification should always be defined here
817-
const displayedErrorMessage =
818-
transformByQState.getJobFailureErrorNotification() ?? CodeWhispererConstants.failedToCompleteJobNotification
819816
transformByQState.setJobFailureErrorChatMessage(
820817
transformByQState.getJobFailureErrorChatMessage() ?? CodeWhispererConstants.failedToCompleteJobChatMessage
821818
)
822-
void vscode.window
823-
.showErrorMessage(displayedErrorMessage, CodeWhispererConstants.amazonQFeedbackText)
824-
.then((choice) => {
825-
if (choice === CodeWhispererConstants.amazonQFeedbackText) {
826-
void submitFeedback(
827-
placeholder,
828-
CodeWhispererConstants.amazonQFeedbackKey,
829-
getFeedbackCommentData()
830-
)
831-
}
832-
})
833819
} else {
834820
transformByQState.setToCancelled()
835821
transformByQState.setPolledJobStatus('CANCELLED')

packages/core/src/codewhisperer/models/model.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,6 @@ export class TransformByQState {
760760
private intervalId: NodeJS.Timeout | undefined = undefined
761761

762762
private refreshInProgress: boolean = false
763-
private blockedByRefresh: boolean = false
764763

765764
public isNotStarted() {
766765
return this.transformByQState === TransformByQStatus.NotStarted
@@ -790,10 +789,6 @@ export class TransformByQState {
790789
return this.refreshInProgress
791790
}
792791

793-
public wasBlockedByRefresh() {
794-
return this.blockedByRefresh
795-
}
796-
797792
public getHasSeenTransforming() {
798793
return this.hasSeenTransforming
799794
}
@@ -992,10 +987,6 @@ export class TransformByQState {
992987
this.refreshInProgress = inProgress
993988
}
994989

995-
public setBlockedByRefresh(blocked: boolean): void {
996-
this.blockedByRefresh = blocked
997-
}
998-
999990
public setHasSeenTransforming(hasSeen: boolean) {
1000991
this.hasSeenTransforming = hasSeen
1001992
}

packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import { AbsolutePathDetectedError } from '../../../amazonqGumby/errors'
1717
import { getLogger } from '../../../shared/logger/logger'
1818
import AdmZip from 'adm-zip'
1919
import { IManifestFile } from './humanInTheLoopManager'
20-
import { HistoryObject } from './transformationHubViewProvider'
21-
import { isWithin30Days } from '../../../shared/datetime'
2220

2321
export async function getDependenciesFolderInfo(): Promise<FolderInfo> {
2422
const dependencyFolderName = `${CodeWhispererConstants.dependencyFolderName}${globals.clock.Date.now()}`
@@ -184,34 +182,6 @@ export async function openBuildLogFile() {
184182
await vscode.window.showTextDocument(doc)
185183
}
186184

187-
export function readHistoryFile(): HistoryObject[] {
188-
const history: HistoryObject[] = []
189-
const jobHistoryFilePath = path.join(os.homedir(), '.aws', 'transform', 'transformation-history.tsv')
190-
if (existsSync(jobHistoryFilePath)) {
191-
const historyFile = readFileSync(jobHistoryFilePath, { encoding: 'utf8', flag: 'r' })
192-
const jobs = historyFile.split('\n')
193-
jobs.shift() // removes headers
194-
195-
// Process from end, stop at 10 valid entries
196-
for (let i = jobs.length - 1; i >= 0 && history.length < 10; i--) {
197-
const job = jobs[i]
198-
if (job && isWithin30Days(job.split('\t')[0])) {
199-
const jobInfo = job.split('\t')
200-
history.push({
201-
startTime: jobInfo[0],
202-
projectName: jobInfo[1],
203-
status: jobInfo[2],
204-
duration: jobInfo[3],
205-
diffPath: jobInfo[4],
206-
summaryPath: jobInfo[5],
207-
jobId: jobInfo[6],
208-
})
209-
}
210-
}
211-
}
212-
return history
213-
}
214-
215185
export async function createPomCopy(
216186
dirname: string,
217187
pomFileVirtualFileReference: vscode.Uri,

0 commit comments

Comments
 (0)