Skip to content

Commit 9ab97b6

Browse files
authored
Merge pull request #31 from piercus/develop
Develop
2 parents aae887c + 4edf3d7 commit 9ab97b6

7 files changed

Lines changed: 3852 additions & 2866 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22
node_js:
33
- '12'
4+
- '14'
45
install:
56
- npm install -g codecov nyc
67
- npm install

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ const worker = new StepFunctionWorker({
4040

4141
Since version **3.0**, `concurrency` has been replaced by `poolConcurrency` and `taskConcurrency`.
4242

43-
* `taskConcurrency` (`null` means Infinite)
43+
* `poolConcurrency` is the maximum number of parallel getActivity, http request (see [`sdk.getActivity`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/StepFunctions.html#getActivityTask-property)) (default: `1`)
4444

45-
It represent the maximum number of parallel tasks done by the worker (default: `null`).
45+
Increase this to have a more responsive worker, decrease this to consume less http connections.
4646

47-
* `poolConcurrency` is the maximum number of parallel getActivity, http request (see [`sdk.getActivity`](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/StepFunctions.html#getActivityTask-property)) (default: `1`)
47+
* `taskConcurrency` (`null` means Infinite)
4848

49-
Increase this to have a more responsive worker.
49+
It represent the maximum number of parallel tasks done by the worker (default: equals to `poolConcurrency`).
5050

51-
Anyway, you should always have `poolConcurrency` < `taskConcurrency`.
51+
Anyway, you should always have `poolConcurrency` <= `taskConcurrency`.
5252

5353
#### Set the Region
5454

lib/worker.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,39 @@ function Worker(options) {
3232
throw (new Error('activityArn is mandatory inside Worker'));
3333
}
3434

35-
if (typeof (options.concurrency) === 'number') {
36-
throw (new TypeError('step-function-worker is not supporting `concurrency` parameter since version 3.0, see README.md'));
37-
}
38-
39-
this.poolConcurrency = typeof (options.poolConcurrency) === 'number' ? options.poolConcurrency : 1;
40-
this.taskConcurrency = typeof (options.taskConcurrency) === 'number' ? options.taskConcurrency : null;
41-
42-
this.activityArn = options.activityArn;
43-
this.workerName = options.workerName;
4435
this.logger = options.logger || {
4536
debug() {},
4637
info() {},
4738
warn: console.warn,
4839
error: console.error
4940
};
41+
42+
if (typeof (options.concurrency) === 'number') {
43+
// To uncomment in the future
44+
// throw (new TypeError('step-function-worker `concurrency` parameter is deprectated since version 3.0, see README.md'));
45+
this.logger.warn('[step-function-worker] `concurrency` parameter is deprectated since version 3.0 please use `poolConcurrency` instead, see README.md');
46+
if (typeof (options.poolConcurrency) !== 'number') {
47+
options.poolConcurrency = options.concurrency;
48+
}
49+
}
50+
51+
this.poolConcurrency = typeof (options.poolConcurrency) === 'number' ? options.poolConcurrency : 1;
52+
this.taskConcurrency = typeof (options.taskConcurrency) === 'number' ? options.taskConcurrency : this.poolConcurrency;
53+
54+
if (this.poolConcurrency > this.taskConcurrency) {
55+
throw (new Error(`poolConcurrency (${this.poolConcurrency}) < taskConcurrency (${this.taskConcurrency}) is invalid`));
56+
}
57+
58+
this.workerName = options.workerName;
59+
60+
this.activityArn = options.activityArn;
61+
5062
this.fn = options.fn;
5163
this._poolers = [];
5264
this._tasks = [];
5365

5466
if (typeof (this.fn) !== 'function') {
55-
throw (new TypeError('worker does not define any function'));
67+
throw (new TypeError(`fn parameter should be a function (currently ${typeof (this.fn)})`));
5668
}
5769

5870
const {region} = parser(options.activityArn);
@@ -79,7 +91,7 @@ function Worker(options) {
7991
/**
8092
* Start the worker pooling for new tasks
8193
* @param {function} cb callback(err)
82-
* @returns {Promise}
94+
* @returns {Promise} empty Promise
8395
*/
8496
Worker.prototype.start = function () {
8597
this.increasePool();

0 commit comments

Comments
 (0)