Skip to content

Commit

Permalink
exp backoff on fetch + more debug details
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner committed Sep 20, 2024
1 parent 4b99581 commit 5e2e956
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9665,7 +9665,7 @@ async function getUrlResponse(url, headers, attempt = 1) {
const contentType = response.headers.get('content-type') || ''

if (!response.ok) {
throw new Error(`Got ${response.statusCode} from ${url}`)
throw new Error(response.statusText)
}

if (contentType.indexOf('application/json') !== -1) {
Expand All @@ -9674,9 +9674,12 @@ async function getUrlResponse(url, headers, attempt = 1) {
return response.text()
}
} catch (err) {
core.debug(`Error fetching from ${url}: ${err}`)

if (attempt <= MAX_HTTP_RETRIES) {
core.debug(`Error during fetch. Retrying in 1000ms: ${err}`)
await new Promise((resolve) => setTimeout(resolve, 1000))
const delay = attempt * 2 * 1000
core.debug(`Error during fetch. Retrying in ${delay}ms`)
await new Promise((resolve) => setTimeout(resolve, delay))
return getUrlResponse(url, headers, attempt + 1)
} else {
throw err
Expand Down
9 changes: 6 additions & 3 deletions src/setup-beam.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ async function getUrlResponse(url, headers, attempt = 1) {
const contentType = response.headers.get('content-type') || ''

if (!response.ok) {
throw new Error(`Got ${response.statusCode} from ${url}`)
throw new Error(response.statusText)
}

if (contentType.indexOf('application/json') !== -1) {
Expand All @@ -574,9 +574,12 @@ async function getUrlResponse(url, headers, attempt = 1) {
return response.text()
}
} catch (err) {
core.debug(`Error fetching from ${url}: ${err}`)

if (attempt <= MAX_HTTP_RETRIES) {
core.debug(`Error during fetch. Retrying in 1000ms: ${err}`)
await new Promise((resolve) => setTimeout(resolve, 1000))
const delay = attempt * 2 * 1000
core.debug(`Error during fetch. Retrying in ${delay}ms`)
await new Promise((resolve) => setTimeout(resolve, delay))
return getUrlResponse(url, headers, attempt + 1)
} else {
throw err
Expand Down

0 comments on commit 5e2e956

Please sign in to comment.