Skip to content

Commit

Permalink
add retries properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ayys committed Feb 7, 2024
1 parent 7cf5491 commit ca9b4a9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

40 changes: 20 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ const main = async () =>
info(`Downloaded ${transferred}K out of ${total}K (${percent}%)`);
};
const url = isWindows ? 'https://win.wasmer.io' : 'https://get.wasmer.io';
await pipeline(
got.stream(url, {
retry: {
limit: 10,
errorCodes: [
'ETIMEDOUT',
'ECONNRESET',
'EADDRINUSE',
'ECONNREFUSED',
'EPIPE',
'ENOTFOUND',
'ENETUNREACH',
'EAI_AGAIN',
'ERR_NON_2XX_3XX_RESPONSE',
],
let retryAttempts = 0;
const maxRetryAttempts = 10;

while (retryAttempts < maxRetryAttempts) {
try {
await pipeline(
got.stream(url).on('downloadProgress', progressHandler),
createWriteStream(tmp, {
mode: 0o655
})
);
console.log('Downloaded installer.');
break;
}
catch (error) {
retryAttempts++;
if (retryAttempts >= maxRetryAttempts) {
throw new Error(`Failed to download installer after ${retryAttempts} attempts.\nLast error: ${error}`);
}
}).on('downloadProgress', progressHandler),
createWriteStream(tmp, {
mode: 0o655
})
);
}
}
endGroup();

info('Downloaded installer.');
Expand Down

0 comments on commit ca9b4a9

Please sign in to comment.