Skip to content

Commit 2e38490

Browse files
committed
Retry downloading/unzipping upon failure
This adds retry logic with an exponential back-off. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f1c8bc5 commit 2e38490

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/downloader.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,30 @@ export async function get(
240240
)
241241
}
242242
const url = filtered[0].resource.downloadUrl
243-
await unzip(
244-
url,
245-
`${artifactName}/`,
246-
outputDirectory,
247-
verbose,
248-
flavor === 'full' ? unpackTarXZInZipFromURL : undefined
249-
)
243+
let delayInSeconds = 1
244+
for (;;) {
245+
try {
246+
await unzip(
247+
url,
248+
`${artifactName}/`,
249+
outputDirectory,
250+
verbose,
251+
flavor === 'full' ? unpackTarXZInZipFromURL : undefined
252+
)
253+
break
254+
} catch (e) {
255+
delayInSeconds *= 2
256+
if (delayInSeconds >= 60) {
257+
throw e
258+
}
259+
process.stderr.write(
260+
`Encountered problem downloading/extracting ${url}: ${e}; Retrying in ${delayInSeconds} seconds...\n`
261+
)
262+
await new Promise((resolve, _reject) =>
263+
setTimeout(resolve, delayInSeconds * 1000)
264+
)
265+
}
266+
}
250267
}
251268
return {artifactName, download, id}
252269
}

0 commit comments

Comments
 (0)