Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW (Extension) @W-16371431@ Poll ApexGuru API and show the response as diagnostic #115

Merged
merged 7 commits into from
Aug 7, 2024

Conversation

jag-j
Copy link
Collaborator

@jag-j jag-j commented Aug 6, 2024

No description provided.

@@ -80,9 +80,9 @@ export async function run(): Promise<void> {
// This is why we manually set it to 0 earlier.
await nyc.checkCoverage({
branches: 70,
lines: 80,
lines: 70,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interim fix. As I add the quick-fix code and have some end-to-end tests, this will come up again.

const requestId = await initiateApexGuruRequest(selection, outputChannel);
// TODO: Logging the request Id for easy QA. Future stories will use this requestId to poll and retrieve the Apex Guru report.
outputChannel.appendLine('***Apex Guru request Id:***' + requestId);
return await vscode.window.withProgress({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "return" for?

I'm assuming this method has a return signature of Promise. So this return just adds confusion to the code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is unnecessary. Will remove.

} catch (e) {
const errMsg = e instanceof Error ? e.message : e as string;
outputChannel.appendLine('***Apex Guru initiate request failed***');
outputChannel.appendLine(errMsg);
}
}

export async function initiateApexGuruRequest(selection: vscode.Uri, outputChannel: vscode.LogOutputChannel): Promise<string> {
export async function pollAndGetApexGuruResponse(connection: Connection, requestId: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, do you mind adding in the return types to the signature? I'm guessing this returns ApexGuruQueryResponse?

Comment on lines 73 to 74
const retryInterval = Constants.APEX_GURU_RETRY_INTERVAL;
let retryCount = Constants.APEX_GURU_RETRY_COUNT;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a retryCount and a retryInterval..

Can we just have a pollInterval and a timeOut.

Basically, the way javascript works and the way the request works... the pollInterval is just the minimum wait time - not the exact wait time. So we could end up waiting way longer than we should if you base the final timeout on the retry count.

let retryCount = Constants.APEX_GURU_RETRY_COUNT;

while (retryCount > 0) {
queryResponse = await connection.request({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the request method allow us to send in a connection timeout in case the server freezes? Ideally the individual request timeout should always be close to totalTimeout - currentDuration

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I think this could be one of the requirements we could ask from the Apex Guru team.

Comment on lines 88 to 90
} catch (error) {
await new Promise(resolve => setTimeout(resolve, retryIntervalInMillis));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't want to lose this error. I don't think we need a catch statement here do we? Do we care to do retries on error? I didn't think we cared. But if we do, then let's not lose this error. Store it as the last error found... so that if we reach line 95 we can throw the actual error.

…as diagnostic - add test to improve coverage & disable branch test coverage check
const startTime = Date.now();
while ((Date.now() - startTime) < maxWaitTimeInSeconds * 1000) {
try {
queryResponse = await connection.request({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not only follow up with the folks who own this request method regarding the response code... but we should also ask if we can please send in a connection timeout value to ensure that if the server goes down... it isn't going past our remaining timeout time.

@jag-j jag-j merged commit f1ea764 into dev Aug 7, 2024
7 checks passed
@jag-j jag-j deleted the jj/W-16371431_1 branch August 7, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants