Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVSB-17157 - retry up to X times on error #21

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/functions/retroGenInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {StreamService} from "../services/StreamService";
* @param context - λ Context
* @param callback - callback function
*/
const retroGenInit: Handler = async (event: any, context?: Context, callback?: Callback): Promise<void | Array<PromiseResult<SendMessageResult, AWSError>>> => {
const retroGenInit: Handler = async (event: any, context?: Context, callback?: Callback): Promise<void | Array<PromiseResult<SendMessageResult, AWSError>>> => {
if (!event) {
console.error("ERROR: event is not defined.");
return;
Expand All @@ -31,10 +31,13 @@ const retroGenInit: Handler = async (event: any, context?: Context, callback?: C
});

return Promise.all(sendMessagePromises)
.catch((error: AWSError) => {
console.error(error);
throw error;
});
.catch((error: AWSError) => {
console.error(error);
console.log("records");
console.log(records);
// Lambda will retry up to X times or until the message expires, after which the message will be sent to the dlq.
throw error;
});
};

export {retroGenInit};
9 changes: 9 additions & 0 deletions tests/unit/retroGenInitFunction.unitTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ describe("retroGenInit Function", () => {
jest.restoreAllMocks();
jest.resetModuleRegistry();
});

describe("if the event is undefined", () => {
it("should return undefined", async () => {
expect.assertions(1);
const result = await retroGenInit(undefined, ctx, () => { return; });
expect(result).toBe(undefined);
});
});

describe("with good event", () => {
it("should invoke SQS service with correct params", async () => {
const sendMessage = jest.fn().mockResolvedValue("Success");
Expand Down