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

Add pollingWaitTimeMs to UpdatableOptions #436

Merged
merged 4 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Returns the current polling state of the consumer: `true` if it is actively poll

Updates the provided option with the provided value.

Please note that update of `pollingWaitTimeMs` will take effect only on next poll cycle.
maximpoleley marked this conversation as resolved.
Show resolved Hide resolved

You can [find out more about this here](https://bbc.github.io/sqs-consumer/classes/Consumer.html#updateOption).

### Events
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ export interface ConsumerOptions {
export type UpdatableOptions =
| 'visibilityTimeout'
| 'batchSize'
| 'waitTimeSeconds';
| 'waitTimeSeconds'
| 'pollingWaitTimeMs';

export interface StopOptions {
/**
Expand Down
5 changes: 5 additions & 0 deletions src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ function validateOption(
throw new Error('waitTimeSeconds must be between 0 and 20.');
}
break;
case 'pollingWaitTimeMs':
if (value < 0) {
throw new Error('pollingWaitTimeMs must be greater than 0.');
}
break;
default:
if (strict) {
throw new Error(`The update ${option} cannot be updated`);
Expand Down
28 changes: 28 additions & 0 deletions test/tests/consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,34 @@ describe('Consumer', () => {
sandbox.assert.notCalled(optionUpdatedListener);
});

it('updates the pollingWaitTimeMs option and emits an event', () => {
const optionUpdatedListener = sandbox.stub();
consumer.on('option_updated', optionUpdatedListener);

consumer.updateOption('pollingWaitTimeMs', 1000);

assert.equal(consumer.pollingWaitTimeMs, 1000);

sandbox.assert.calledWithMatch(
optionUpdatedListener,
'pollingWaitTimeMs',
1000
);
});

it('does not update the pollingWaitTimeMs if the value is less than 0', () => {
const optionUpdatedListener = sandbox.stub();
consumer.on('option_updated', optionUpdatedListener);

assert.throws(() => {
consumer.updateOption('pollingWaitTimeMs', -1);
}, 'pollingWaitTimeMs must be greater than 0.');

assert.equal(consumer.pollingWaitTimeMs, 0);

sandbox.assert.notCalled(optionUpdatedListener);
});

it('throws an error for an unknown option', () => {
consumer = new Consumer({
region: REGION,
Expand Down
Loading