Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
13bfrancis committed Jan 28, 2025
1 parent 78e253c commit ea64d5c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/lambda/processEmails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,27 @@ export async function processAndSendEmails(
});

const sec = await getSecret(config.emailAddressLookupSecretName);
const item = await os.getItem(config.osDomain, getOsNamespace("main"), id);
async function retry<T>(fn: () => Promise<T>, retries: number, delay: number): Promise<T> {
for (let attempt = 0; attempt < retries; attempt++) {
try {
return await fn(); // Try to execute the function
} catch (error) {
if (attempt < retries - 1) {
console.warn(`Attempt ${attempt + 1} failed. Retrying in ${delay}ms...`);
await new Promise((res) => setTimeout(res, delay)); // Wait before retrying
} else {
throw error; // Re-throw error after exhausting retries
}
}
}
throw new Error("Retry mechanism failed unexpectedly."); // Safety guard
}

const item = await retry(
() => os.getItem(config.osDomain, getOsNamespace("main"), id),
10,
10 * 1000,
);

if (!item?.found || !item?._source) {
console.log(`The package was not found for id: ${id}. Doing nothing.`);
Expand Down

0 comments on commit ea64d5c

Please sign in to comment.