MCPcopy Index your code
hub / github.com/scality/cloudserver / gcpRetryCall

Function gcpRetryCall

tests/functional/raw-node/utils/gcpUtils.js:17–44  ·  view source on GitHub ↗
(callFn, retryOptions)

Source from the content-addressed store, hash-verified

15 err && (err.name === 'SlowDown' || err.$metadata?.httpStatusCode === 429);
16
17async function gcpRetryCall(callFn, retryOptions) {
18 const {
19 // 6 attempts with exponential backoff gives up to ~63s of total wait.
20 maxAttempts = 6,
21 shouldRetry = defaultShouldRetry,
22 getDelayMs = attempt => Math.pow(2, attempt) * 1000,
23 } = retryOptions || {};
24
25 let lastError;
26 for (let attempt = 0; attempt < maxAttempts; attempt++) {
27 try {
28 return await callFn();
29 } catch (err) {
30 lastError = err;
31 if (!shouldRetry(err, attempt) || attempt === maxAttempts - 1) {
32 throw err;
33 }
34 const delay = getDelayMs(attempt);
35 process.stdout.write(
36 'Retryable error from GCP, retrying in ' +
37 `${delay}ms (attempt ${attempt + 1}): ${err}\n`);
38
39 await new Promise(resolve => setTimeout(resolve, delay));
40 }
41 }
42
43 throw lastError;
44}
45
46async function gcpRetry(gcpClient, command, retryOptions, cb) {
47 if (cb) {

Callers 3

gcpRetryFunction · 0.85
gcpUploadWithRetryFunction · 0.85

Calls 2

callFnFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected