Skip to content

Commit

Permalink
Issue #269 - fix the input to ChangeVisibilityTimeout to not include …
Browse files Browse the repository at this point in the history
…the elapsed seconds
  • Loading branch information
charlescapps committed Aug 13, 2021
1 parent 3cafbb7 commit 6a23fab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 6 additions & 8 deletions src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 6a23fab

Please sign in to comment.