Skip to content

Commit c908ed9

Browse files
committed
Retry when querying Azure Pipelines' artifacts
We encountered a problem where Azure Pipelines would return a 503. This is obviously a transient error, and we want to be gentle and nice about it and just retry a couple times, with a nice and easy exponential back-off. Sadly, `node-fetch` does not provide that functionality out of the box. But there is a small wrapper around it that does. We just need to add Typescript declarations, and use it, and we're all set. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 6598596 commit c908ed9

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"vstfs://.*"
1111
],
1212
"cSpell.words": [
13+
"Backoff",
1314
"MSYSTEM",
1415
"Pacman",
1516
"autodrain",

src/downloader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {Readable} from 'stream'
44
import unzipper from 'unzipper'
55
import {spawn} from 'child_process'
66
import {delimiter} from 'path'
7-
import fetch from 'node-fetch'
7+
import fetch from '@adobe/node-fetch-retry'
88

99
const gitForWindowsUsrBinPath = 'C:/Program Files/Git/usr/bin'
1010
const gitForWindowsMINGW64BinPath = 'C:/Program Files/Git/mingw64/bin'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Type definitions for node-fetch 1.1.0
2+
// Project: https://github.com/adobe/node-fetch-retry
3+
4+
/// <reference types="node" />
5+
6+
declare module '@adobe/node-fetch-retry' {
7+
import {RequestInfo, RequestInit, Response} from 'node-fetch'
8+
9+
interface RequestInitWithRetry extends RequestInit {
10+
retryOptions?: {
11+
retryMaxDuration?: number
12+
retryInitialDelay?: number
13+
retryBackoff?: number
14+
retryOnHttpResponse?: (response: Response) => boolean
15+
socketTimeout?: number
16+
forceSocketTimeout?: boolean
17+
}
18+
}
19+
20+
function fetch(
21+
url: RequestInfo,
22+
init?: RequestInitWithRetry
23+
): Promise<Response>
24+
25+
export default fetch
26+
}

0 commit comments

Comments
 (0)