sqs-consumer
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -13,2 +13,3 @@ import * as SQS from 'aws-sdk/clients/sqs'; | ||
authenticationErrorTimeout?: number; | ||
pollingWaitTimeMs?: number; | ||
terminateVisibilityTimeout?: boolean; | ||
@@ -33,2 +34,3 @@ sqs?: SQS; | ||
private authenticationErrorTimeout; | ||
private pollingWaitTimeMs; | ||
private terminateVisibilityTimeout; | ||
@@ -35,0 +37,0 @@ private sqs; |
@@ -69,2 +69,3 @@ "use strict"; | ||
this.authenticationErrorTimeout = options.authenticationErrorTimeout || 10000; | ||
this.pollingWaitTimeMs = options.pollingWaitTimeMs || 0; | ||
this.sqs = options.sqs || new SQS({ | ||
@@ -217,3 +218,3 @@ region: options.region || process.env.AWS_REGION || 'eu-west-1' | ||
}; | ||
let pollingTimeout = 0; | ||
let currentPollingTimeout = this.pollingWaitTimeMs; | ||
this.receiveMessage(receiveParams) | ||
@@ -225,7 +226,7 @@ .then(this.handleSqsResponse) | ||
debug('There was an authentication error. Pausing before retrying.'); | ||
pollingTimeout = this.authenticationErrorTimeout; | ||
currentPollingTimeout = this.authenticationErrorTimeout; | ||
} | ||
return; | ||
}).then(() => { | ||
setTimeout(this.poll, pollingTimeout); | ||
setTimeout(this.poll, currentPollingTimeout); | ||
}).catch((err) => { | ||
@@ -232,0 +233,0 @@ this.emit('error', err); |
{ | ||
"name": "sqs-consumer", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"description": "Build SQS-based Node applications without the boilerplate", | ||
@@ -43,7 +43,7 @@ "main": "dist/index.js", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.1.0", | ||
"nyc": "^14.1.1", | ||
"p-event": "^2.1.0", | ||
"sinon": "^7.2.2", | ||
"ts-node": "^3.3.0", | ||
"tslint": "^5.12.1", | ||
"tslint": "^5.17.0", | ||
"tslint-config-airbnb": "^5.3.1", | ||
@@ -50,0 +50,0 @@ "tslint-microsoft-contrib": "^5.0.3", |
@@ -109,2 +109,3 @@ # sqs-consumer | ||
* `authenticationErrorTimeout` - _Number_ - The duration (in milliseconds) to wait before retrying after an authentication error (defaults to `10000`). | ||
* `pollingWaitTimeMs` - _Number_ - The duration (in milliseconds) to wait before repolling the queue (defaults to `0`). | ||
* `sqs` - _Object_ - An optional [AWS SQS](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html) object to use if you need to configure the client manually | ||
@@ -111,0 +112,0 @@ |
@@ -21,3 +21,3 @@ import { AWSError } from 'aws-sdk'; | ||
interface TimeoutResonse { | ||
interface TimeoutResponse { | ||
timeout: NodeJS.Timeout; | ||
@@ -27,3 +27,3 @@ pending: Promise<void>; | ||
function createTimeout(duration: number): TimeoutResonse[] { | ||
function createTimeout(duration: number): TimeoutResponse[] { | ||
let timeout; | ||
@@ -83,2 +83,3 @@ const pending = new Promise((_, reject) => { | ||
authenticationErrorTimeout?: number; | ||
pollingWaitTimeMs?: number; | ||
terminateVisibilityTimeout?: boolean; | ||
@@ -104,2 +105,3 @@ sqs?: SQS; | ||
private authenticationErrorTimeout: number; | ||
private pollingWaitTimeMs: number; | ||
private terminateVisibilityTimeout: boolean; | ||
@@ -123,2 +125,3 @@ private sqs: SQS; | ||
this.authenticationErrorTimeout = options.authenticationErrorTimeout || 10000; | ||
this.pollingWaitTimeMs = options.pollingWaitTimeMs || 0; | ||
@@ -280,3 +283,3 @@ this.sqs = options.sqs || new SQS({ | ||
let pollingTimeout = 0; | ||
let currentPollingTimeout = this.pollingWaitTimeMs; | ||
this.receiveMessage(receiveParams) | ||
@@ -288,7 +291,7 @@ .then(this.handleSqsResponse) | ||
debug('There was an authentication error. Pausing before retrying.'); | ||
pollingTimeout = this.authenticationErrorTimeout; | ||
currentPollingTimeout = this.authenticationErrorTimeout; | ||
} | ||
return; | ||
}).then(() => { | ||
setTimeout(this.poll, pollingTimeout); | ||
setTimeout(this.poll, currentPollingTimeout); | ||
}).catch((err) => { | ||
@@ -295,0 +298,0 @@ this.emit('error', err); |
@@ -10,2 +10,3 @@ import { assert } from 'chai'; | ||
const AUTHENTICATION_ERROR_TIMEOUT = 20; | ||
const POLLING_TIMEOUT = 100; | ||
@@ -318,2 +319,27 @@ function stubResolve(value?: any): any { | ||
it('waits before repolling when a polling timeout is set', async () => { | ||
consumer = new Consumer({ | ||
queueUrl: 'some-queue-url', | ||
region: 'some-region', | ||
handleMessage, | ||
sqs, | ||
authenticationErrorTimeout: 20, | ||
pollingWaitTimeMs: 100 | ||
}); | ||
return new Promise((resolve) => { | ||
const timings = []; | ||
const timeListener = sandbox.stub().callsFake(() => timings.push(new Date())); | ||
timeListener.onThirdCall().callsFake(() => { | ||
consumer.stop(); | ||
sandbox.assert.calledThrice(sqs.receiveMessage); | ||
assert.isAtLeast(timings[1] - timings[0], POLLING_TIMEOUT); | ||
resolve(); | ||
}); | ||
consumer.on('message_received', timeListener); | ||
consumer.start(); | ||
}); | ||
}); | ||
it('fires a message_received event when a message is received', async () => { | ||
@@ -320,0 +346,0 @@ consumer.start(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
85771
1419
146