Skip to content

Instantly share code, notes, and snippets.

@Gabri3l
Created July 27, 2022 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gabri3l/f9992cec434f50bd9b43d0d774a2a6ee to your computer and use it in GitHub Desktop.
Save Gabri3l/f9992cec434f50bd9b43d0d774a2a6ee to your computer and use it in GitHub Desktop.
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