Skip to content

Commit 112b24a

Browse files
authored
feat: make getFile retry downloads (#1854)
1 parent 18c30ee commit 112b24a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/extester/src/util/download.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { promisify } from 'util';
2020
import stream from 'stream';
2121
import { HttpProxyAgent, HttpsProxyAgent } from 'hpagent';
2222

23+
const retryCount = 3;
2324
const httpProxyAgent = !process.env.HTTP_PROXY
2425
? undefined
2526
: new HttpProxyAgent({
@@ -40,6 +41,9 @@ const options = {
4041
http: httpProxyAgent,
4142
https: httpsProxyAgent,
4243
},
44+
retry: {
45+
limit: retryCount,
46+
},
4347
};
4448

4549
export class Download {
@@ -53,6 +57,10 @@ export class Download {
5357
let lastTick = 0;
5458
const got = (await import('got')).default;
5559
const dlStream = got.stream(uri, options);
60+
// needed in order to enable retry feature:
61+
dlStream.once('retry', (newRetryCount: number, error) => {
62+
console.warn(`retry(${newRetryCount}): Failed getting ${uri} due to ${error}`);
63+
});
5664
if (progress) {
5765
dlStream.on('downloadProgress', ({ transferred, total, percent }) => {
5866
const currentTime = Date.now();

0 commit comments

Comments
 (0)