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

chore: Refactor message processing in SQSHandler and add waitTimePolling option #56

Merged
Merged
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
3 changes: 1 addition & 2 deletions src/ext/sqs/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const DEFAULT_MAX_NUMBER_OF_MESSAGES = 10;

export const DEFAULT_WAIT_TIME_SECONDS = 20;

export const DEFAULT_VISIBILITY_TIMEOUT = 30;
export const DEFAULT_WAIT_TIME_POLLING = 10000;
4 changes: 3 additions & 1 deletion src/ext/sqs/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import logging from '../../logging';
import { AbstractMessageTranslator } from '../../message-translators';
import { timeout } from '../../utils';
import { BaseSQS } from './base';
import { DEFAULT_WAIT_TIME_POLLING } from './constants';
import { SQSProvider } from './providers';
import { SQSClientOptions } from './types';

Expand All @@ -15,7 +16,8 @@ export class SQSHandler extends BaseSQS {
super(clientOptions);
this.provider = new SQSProvider(queueName, clientOptions);
this.messageTranslator = clientOptions.messageTranslator;
this.pollingWaitTimeMs = 30000;
this.pollingWaitTimeMs =
clientOptions.waitTimePolling || DEFAULT_WAIT_TIME_POLLING;
}

async stop(): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions src/ext/sqs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type SQSClientOptions = {
prefixBasedQueues?: boolean;
maxNumberOfMessages?: number;
waitTimeSeconds?: number;
waitTimePolling?: number;
};

export type SQSMessageAttributes = {
Expand Down
16 changes: 16 additions & 0 deletions tests/ext/sqs/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ describe('SQSHandler', () => {
expect(sqsHandler.messageTranslator).toBeDefined();
expect(sqsHandler.messageTranslator).toBeInstanceOf(SQSMessageTranslator);
});

it.each([
[10000, 10000],
[20000, 20000],
[undefined, 10000]
])(
`should create a new SQSHandler with waitTimePolling %s`,
(waitTimePolling, expected) => {
sqsHandler = new SQSHandler('queueName', {
visibilityTimeout: 10,
messageTranslator: new SQSMessageTranslator(),
waitTimePolling
});
expect(sqsHandler.pollingWaitTimeMs).toBe(expected);
}
);
});

describe('start', () => {
Expand Down
Loading