Skip to content

Commit

Permalink
only retry on 5xx status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Brignull committed May 1, 2020
1 parent e52e34b commit 0c4fc16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
18 changes: 12 additions & 6 deletions lib/upload-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,36 @@ async function uploadPayload(payload) {
const res: http.HttpClientResponse = await client.put(url, payload);
core.debug('response status: ' + res.message.statusCode);

if (res.message.statusCode === 202) {
const statusCode = res.message.statusCode;
if (statusCode === 202) {
core.info("Successfully uploaded results");
return;
}

const requestID = res.message.headers["x-github-request-id"];

// On any other status code that's not 5xx mark the upload as failed
if (!statusCode || statusCode < 500 || statusCode >= 600) {
core.setFailed('Upload failed (' + requestID + '): ' + await res.readBody());
return;
}

// On a 5xx status code we may retry the request
if (attempt < backoffPeriods.length) {
// Log the failure as a warning but don't mark the action as failed yet
core.warning('Upload attempt (' + (attempt + 1) + ' of ' + (backoffPeriods.length + 1) +
') failed (' + requestID + '). Retrying in ' + backoffPeriods[attempt] + ' seconds: ' +
await res.readBody());
// Sleep for the backoff period
await new Promise(r => setTimeout(r, backoffPeriods[attempt] * 1000));
continue;

} else if (res.message.statusCode === 500) {
// If the upload fails with 500 then we assume it is a temporary problem
} else {
// If the upload fails with 5xx then we assume it is a temporary problem
// with turbo-scan and not an error that the user has caused or can fix.
// We avoid marking the job as failed to avoid breaking CI workflows.
core.error('Upload failed (' + requestID + '): ' + await res.readBody());

} else {
core.setFailed('Upload failed (' + requestID + '): ' + await res.readBody());
return;
}
}
}
Expand Down

0 comments on commit 0c4fc16

Please sign in to comment.