diff --git a/package.json b/package.json index 1d77c7b7..33eb2c90 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sqs-consumer", - "version": "5.5.0", + "version": "5.5.1", "description": "Build SQS-based Node applications without the boilerplate", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/consumer.ts b/src/consumer.ts index 1b941730..5d91f0d6 100644 --- a/src/consumer.ts +++ b/src/consumer.ts @@ -203,8 +203,8 @@ export class Consumer extends EventEmitter { let heartbeat; try { if (this.heartbeatInterval) { - heartbeat = this.startHeartbeat(async (elapsedSeconds) => { - return this.changeVisabilityTimeout(message, elapsedSeconds + this.visibilityTimeout); + heartbeat = this.startHeartbeat(async () => { + return this.changeVisabilityTimeout(message, this.visibilityTimeout); }); } await this.executeHandler(message); @@ -338,8 +338,8 @@ export class Consumer extends EventEmitter { let heartbeat; try { if (this.heartbeatInterval) { - heartbeat = this.startHeartbeat(async (elapsedSeconds) => { - return this.changeVisabilityTimeoutBatch(messages, elapsedSeconds + this.visibilityTimeout); + heartbeat = this.startHeartbeat(async () => { + return this.changeVisabilityTimeoutBatch(messages, this.visibilityTimeout); }); } await this.executeBatchHandler(messages); @@ -405,11 +405,9 @@ export class Consumer extends EventEmitter { } } - private startHeartbeat(heartbeatFn: (elapsedSeconds: number) => void): NodeJS.Timeout { - const startTime = Date.now(); + private startHeartbeat(heartbeatFn: () => void): NodeJS.Timeout { return setInterval(() => { - const elapsedSeconds = Math.ceil((Date.now() - startTime) / 1000); - heartbeatFn(elapsedSeconds); + heartbeatFn(); }, this.heartbeatInterval * 1000); } } diff --git a/test/consumer.ts b/test/consumer.ts index acc91f05..990b7651 100644 --- a/test/consumer.ts +++ b/test/consumer.ts @@ -623,7 +623,7 @@ describe('Consumer', () => { }); - it('extends visibility timeout for long running handler functions', async () => { + it('uses the correct visibility timeout for long running handler functions', async () => { consumer = new Consumer({ queueUrl: 'some-queue-url', region: 'some-region', @@ -641,17 +641,17 @@ describe('Consumer', () => { sandbox.assert.calledWith(sqs.changeMessageVisibility, { QueueUrl: 'some-queue-url', ReceiptHandle: 'receipt-handle', - VisibilityTimeout: 70 + VisibilityTimeout: 40 }); sandbox.assert.calledWith(sqs.changeMessageVisibility, { QueueUrl: 'some-queue-url', ReceiptHandle: 'receipt-handle', - VisibilityTimeout: 100 + VisibilityTimeout: 40 }); sandbox.assert.calledOnce(clearIntervalSpy); }); - it('extends visibility timeout for long running batch handler functions', async () => { + it('passes in the correct visibility timeout for long running batch handler functions', async () => { sqs.receiveMessage = stubResolve({ Messages: [ { MessageId: '1', ReceiptHandle: 'receipt-handle-1', Body: 'body-1' }, @@ -677,17 +677,17 @@ describe('Consumer', () => { sandbox.assert.calledWith(sqs.changeMessageVisibilityBatch, { QueueUrl: 'some-queue-url', Entries: [ - { Id: '1', ReceiptHandle: 'receipt-handle-1', VisibilityTimeout: 70 }, - { Id: '2', ReceiptHandle: 'receipt-handle-2', VisibilityTimeout: 70 }, - { Id: '3', ReceiptHandle: 'receipt-handle-3', VisibilityTimeout: 70 } + { Id: '1', ReceiptHandle: 'receipt-handle-1', VisibilityTimeout: 40 }, + { Id: '2', ReceiptHandle: 'receipt-handle-2', VisibilityTimeout: 40 }, + { Id: '3', ReceiptHandle: 'receipt-handle-3', VisibilityTimeout: 40 } ] }); sandbox.assert.calledWith(sqs.changeMessageVisibilityBatch, { QueueUrl: 'some-queue-url', Entries: [ - { Id: '1', ReceiptHandle: 'receipt-handle-1', VisibilityTimeout: 100 }, - { Id: '2', ReceiptHandle: 'receipt-handle-2', VisibilityTimeout: 100 }, - { Id: '3', ReceiptHandle: 'receipt-handle-3', VisibilityTimeout: 100 } + { Id: '1', ReceiptHandle: 'receipt-handle-1', VisibilityTimeout: 40 }, + { Id: '2', ReceiptHandle: 'receipt-handle-2', VisibilityTimeout: 40 }, + { Id: '3', ReceiptHandle: 'receipt-handle-3', VisibilityTimeout: 40 } ] }); sandbox.assert.calledOnce(clearIntervalSpy);