Created
July 27, 2022 16:29
-
-
Save Gabri3l/f9992cec434f50bd9b43d0d774a2a6ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function handleRetry( | |
functionToRetry, | |
functionName, | |
operationId, | |
previousAttemptNumber, | |
...args | |
) { | |
try { | |
return functionToRetry(...args); | |
} catch (err) { | |
const maxRetries = context.values.get("MAX_FUNC_RETRIES"); | |
if (previousAttemptNumber === maxRetries - 1) { | |
throw new Error(`Maximum number of attemtps reched (${maxRetries}) for function '${functionName}': ${err.message}`) | |
} | |
const logEntry = { | |
operationId, | |
errorMessage: err.message, | |
timestamp: Date.now(), | |
attemptNumber: previousAttemptNumber + 1, | |
args, | |
functionName, | |
}; | |
const executionLog = context.services | |
.get("mongodb-atlas") | |
.db("experimental") | |
.collection("function_execution_logs"); | |
executionLog.insertOne(logEntry); | |
} | |
} | |
exports = handleRetry; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment