Skip to content

Commit

Permalink
fix: EmptyBatchRequest when stopping and no messages #167
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Nov 23, 2023
1 parent e21c125 commit 791f194
Show file tree
Hide file tree
Showing 6 changed files with 735 additions and 1,412 deletions.
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "squiss-ts",
"version": "5.2.3",
"version": "5.3.0",
"description": "High-volume SQS poller",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -48,40 +48,40 @@
},
"homepage": "https://github.com/PruvoNet/squiss-ts#readme",
"dependencies": {
"@aws-sdk/client-s3": "^3.435.0",
"@aws-sdk/client-sqs": "^3.413.0",
"@aws-sdk/types": "^3.433.0",
"@aws-sdk/client-s3": "^3.456.0",
"@aws-sdk/client-sqs": "^3.454.0",
"@aws-sdk/types": "^3.451.0",
"linked-list": "2.1.0",
"ts-type-guards": "^0.7.0",
"uuid": "^9.0.1"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "1.0.2",
"@types/chai": "^4.3.6",
"@types/chai-as-promised": "^7.1.6",
"@types/mocha": "^10.0.1",
"@types/chai": "^4.3.11",
"@types/chai-as-promised": "^7.1.8",
"@types/mocha": "^10.0.6",
"@types/node": "^16.18.39",
"@types/proxyquire": "^1.3.28",
"@types/uuid": "^9.0.3",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"chai": "^4.3.8",
"@types/proxyquire": "^1.3.31",
"@types/uuid": "^9.0.7",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"delay": "5.0.0",
"dirty-chai": "^2.0.1",
"eslint": "^8.49.0",
"eslint": "^8.54.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsdoc": "^46.6.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"proxyquire": "^2.1.3",
"sinon": "^15.2.0",
"sinon": "^17.0.1",
"sinon-chai": "^3.7.0",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.3.2"
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
Expand Down
5 changes: 4 additions & 1 deletion src/Squiss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,10 @@ export class Squiss extends (EventEmitter as new() => SquissEmitter) {
this._opts.minReceiveBatchSize = Math.min(this._opts.minReceiveBatchSize!, this._opts.receiveBatchSize);
}

private _deleteMessages(batch: IDeleteQueueItem[]): Promise<void> {
private async _deleteMessages(batch: IDeleteQueueItem[]): Promise<void> {
if (batch.length === 0) {
return;
}
return this.getQueueUrl().then((queueUrl) => {
return this.sqs.deleteMessageBatch({
QueueUrl: queueUrl,
Expand Down
11 changes: 9 additions & 2 deletions src/Types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import {Message} from './Message';
import {SQSClientConfig, BatchResultErrorEntry, SQS, SQSServiceException, MessageAttributeValue} from '@aws-sdk/client-sqs'
import {
SQSClientConfig,
BatchResultErrorEntry,
SQS,
SQSServiceException,
MessageAttributeValue,
QueueAttributeName
} from '@aws-sdk/client-sqs'
import {S3, S3ClientConfig} from '@aws-sdk/client-s3'
import {IS3Upload} from './s3Utils';
import {StrictEventEmitter} from './EventEmitterTypesHelper';
Expand Down Expand Up @@ -46,7 +53,7 @@ export type BodyFormat = 'json' | 'plain' | undefined;
export interface ISquissOptions {
receiveBatchSize?: number;
receiveAttributes?: string[];
receiveSqsAttributes?: string[];
receiveSqsAttributes?: QueueAttributeName[];
minReceiveBatchSize?: number;
receiveWaitTimeSecs?: number;
deleteBatchSize?: number;
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* istanbul ignore file */
import {SQS} from '@aws-sdk/client-sqs'
export {SQS}
import {SQS, QueueAttributeName} from '@aws-sdk/client-sqs'
export {SQS, QueueAttributeName}
import {S3} from '@aws-sdk/client-s3'
export {S3}
export {Squiss} from './Squiss';
Expand Down
11 changes: 11 additions & 0 deletions src/test/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,17 @@ describe('index', () => {
spy.should.be.calledTwice();
});
});
it('should not call delete api if no messages after stop', () => {
inst = new SquissPatched({queueUrl: 'foo', deleteBatchSize: 10, deleteWaitMs: 10} as ISquissOptions);
inst!.sqs = new SQSStub() as any as SQS;
const spy = sinon.spy(inst!.sqs, 'deleteMessageBatch');
inst!.start();
return wait().then(() => {
return inst!.stop();
}).then(() => {
spy.should.not.be.called();
});
});
it('requires a Message object be sent to deleteMessage', () => {
inst = new SquissPatched({queueUrl: 'foo', deleteBatchSize: 1} as ISquissOptions);
const promise = inst!.deleteMessage('foo' as any);
Expand Down
Loading

0 comments on commit 791f194

Please sign in to comment.