Skip to content

Commit 4edf3d7

Browse files
authored
Merge pull request #30 from piercus/node14
Node14
2 parents cb75ae9 + 07eb111 commit 4edf3d7

7 files changed

Lines changed: 7703 additions & 4851 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: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
[![Build Status](https://travis-ci.org/piercus/step-function-worker.svg?branch=master)](https://travis-ci.org/piercus/step-function-worker)
2-
1+
[![Build Status](https://app.travis-ci.com/piercus/step-function-worker.svg?branch=master)](https://app.travis-ci.com/piercus/step-function-worker)
32
[![codecov](https://codecov.io/gh/piercus/step-function-worker/branch/master/graph/badge.svg)](https://codecov.io/gh/piercus/step-function-worker)
43

54
# step-function-worker
@@ -41,15 +40,15 @@ const worker = new StepFunctionWorker({
4140

4241
Since version **3.0**, `concurrency` has been replaced by `poolConcurrency` and `taskConcurrency`.
4342

44-
* `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`)
4544

46-
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.
4746

48-
* `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)
4948

50-
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`).
5150

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

5453
#### Set the Region
5554

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)