Merge pull request #2440 from JarLob/patch-1
Retry results download if connection times out
This commit is contained in:
@@ -75,6 +75,10 @@ import {
|
||||
writeRepoStates,
|
||||
} from "./repo-states-store";
|
||||
import { GITHUB_AUTH_PROVIDER_ID } from "../common/vscode/authentication";
|
||||
import { FetchError } from "node-fetch";
|
||||
import { extLogger } from "../common";
|
||||
|
||||
const maxRetryCount = 3;
|
||||
|
||||
export class VariantAnalysisManager
|
||||
extends DisposableObject
|
||||
@@ -613,12 +617,35 @@ export class VariantAnalysisManager
|
||||
});
|
||||
}
|
||||
};
|
||||
await this.variantAnalysisResultsManager.download(
|
||||
variantAnalysis.id,
|
||||
repoTask,
|
||||
this.getVariantAnalysisStorageLocation(variantAnalysis.id),
|
||||
updateRepoStateCallback,
|
||||
);
|
||||
let retry = 0;
|
||||
for (;;) {
|
||||
try {
|
||||
await this.variantAnalysisResultsManager.download(
|
||||
variantAnalysis.id,
|
||||
repoTask,
|
||||
this.getVariantAnalysisStorageLocation(variantAnalysis.id),
|
||||
updateRepoStateCallback,
|
||||
);
|
||||
break;
|
||||
} catch (e) {
|
||||
if (
|
||||
retry++ < maxRetryCount &&
|
||||
e instanceof FetchError &&
|
||||
(e.code === "ETIMEDOUT" || e.code === "ECONNRESET")
|
||||
) {
|
||||
void extLogger.log(
|
||||
`Timeout while trying to download variant analysis with id: ${
|
||||
variantAnalysis.id
|
||||
}. Error: ${getErrorMessage(e)}. Retrying...`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
void extLogger.log(
|
||||
`Failed to download variant analysis after ${retry} attempts.`,
|
||||
);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
repoState.downloadStatus =
|
||||
VariantAnalysisScannedRepositoryDownloadStatus.Failed;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { appendFile, pathExists } from "fs-extra";
|
||||
import { appendFile, pathExists, rm } from "fs-extra";
|
||||
import fetch from "node-fetch";
|
||||
import { EOL } from "os";
|
||||
import { join } from "path";
|
||||
@@ -82,6 +82,9 @@ export class VariantAnalysisResultsManager extends DisposableObject {
|
||||
|
||||
const zipFilePath = join(resultDirectory, "results.zip");
|
||||
|
||||
// in case of restarted download delete possible artifact from previous download
|
||||
await rm(zipFilePath, { force: true });
|
||||
|
||||
const response = await fetch(repoTask.artifactUrl);
|
||||
|
||||
let responseSize = parseInt(response.headers.get("content-length") || "0");
|
||||
|
||||
Reference in New Issue
Block a user