MCPcopy
hub / github.com/serverless/serverless / retryOperation

Function retryOperation

packages/engine/integration/e2e/e2e.test.js:75–120  ·  view source on GitHub ↗
(
  operation,
  validator,
  retries = 5,
  delayMs = 5000,
)

Source from the content-addressed store, hash-verified

73
74// Utility function to retry operations with delay
75const retryOperation = async (
76 operation,
77 validator,
78 retries = 5,
79 delayMs = 5000,
80) => {
81 let lastError
82
83 for (let attempt = 0; attempt < retries; attempt++) {
84 try {
85 const result = await operation()
86
87 // Try to validate the result without failing the test immediately
88 try {
89 validator(result)
90 return result // Success - validation passed
91 } catch (validationError) {
92 // If validation fails, treat it as a retriable error
93 lastError = validationError
94 console.log(
95 `Attempt ${attempt + 1}/${retries} validation failed: ${validationError.message}`,
96 )
97
98 if (attempt < retries - 1) {
99 // Wait before next retry
100 await new Promise((resolve) => setTimeout(resolve, delayMs))
101 continue // Try again
102 } else {
103 throw validationError // Last attempt, re-throw the validation error
104 }
105 }
106 } catch (error) {
107 lastError = error
108 console.log(`Attempt ${attempt + 1}/${retries} failed: ${error.message}`)
109
110 if (attempt < retries - 1) {
111 // Wait before next retry
112 await new Promise((resolve) => setTimeout(resolve, delayMs))
113 } else {
114 throw lastError // All retries failed
115 }
116 }
117 }
118
119 throw lastError // All retries failed
120}
121
122describe('Deploy SCF Service', () => {
123 let config

Callers 1

e2e.test.jsFile · 0.85

Calls 1

logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…