Skip to content

Commit

Permalink
fix(timeout): Fix stack report polling frequency and duration (#338)
Browse files Browse the repository at this point in the history
Fixes stack report polling duration to 20s and polling frequency to 2s.

This PR fixes VSIX side of issue #304. Also it handles new HTTP error code which got introduced part of fabric8-analytics/fabric8-analytics-server#576.
  • Loading branch information
arajkumar authored Sep 3, 2019
1 parent 301258e commit 96f8d09
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ export enum GlobalState {
export const extensionId = 'fabric8-analytics';
// publisher.name from package.json
export const extensionQualifiedId = `redhat.${extensionId}`;
// GET request timeout
export const getRequestTimeout = 20 * 1000; // ms
// GET request polling frequency
export const getRequestPollInterval = 2 * 1000; // ms
5 changes: 5 additions & 0 deletions src/stackAnalysisService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export module stackAnalysisServices {
httpResponse.statusCode
} - ${httpResponse.statusMessage} `;
reject(errorMsg);
} else if (httpResponse.statusCode === 408) {
errorMsg = `Stack analysis request has timed out. Status: ${
httpResponse.statusCode
} - ${httpResponse.statusMessage} `;
reject(errorMsg);
} else {
clearContextInfo(context);
errorMsg = `Failed to trigger application's stack analysis, try in a while. Status: ${
Expand Down
10 changes: 6 additions & 4 deletions src/stackanalysismodule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as vscode from 'vscode';
import * as paths from 'path';

import { Apiendpoint } from './apiendpoint';
import { getRequestTimeout, getRequestPollInterval } from './constants';
import { multimanifestmodule } from './multimanifestmodule';
import { ProjectDataProvider } from './ProjectDataProvider';
import { stackAnalysisServices } from './stackAnalysisService';
Expand Down Expand Up @@ -70,7 +71,7 @@ export module stackanalysismodule {
}stack-analyses/${respId}?user_key=${
Apiendpoint.STACK_API_USER_KEY
}`;
let couterGetSa = 0;
let timeoutCounter = getRequestTimeout / getRequestPollInterval;
const interval = setInterval(() => {
stackAnalysisServices
.getStackAnalysisService(options)
Expand All @@ -85,8 +86,9 @@ export module stackanalysismodule {
}
resolve();
} else {
couterGetSa++;
if (couterGetSa >= 17) {
console.log(`Polling for stack report, remaining count:${timeoutCounter}`);
--timeoutCounter;
if (timeoutCounter <= 0) {
let errMsg = `Failed to trigger application's stack analysis, try in a while.`;
clearInterval(interval);
p.report({
Expand All @@ -106,7 +108,7 @@ export module stackanalysismodule {
handleError(error);
reject(error);
});
}, 7000);
}, getRequestPollInterval);
})
.catch(err => {
p.report({
Expand Down

0 comments on commit 96f8d09

Please sign in to comment.