@@ -2,7 +2,6 @@ const EventEmitter = require('events').EventEmitter;
2
2
const util = require ( 'util' ) ;
3
3
const AWS = require ( 'aws-sdk' ) ;
4
4
5
- const stepfunction = new AWS . StepFunctions ( ) ;
6
5
const Pooler = require ( './pooler.js' ) ;
7
6
const replaceError = require ( './replace-error.js' ) ;
8
7
@@ -15,10 +14,16 @@ const replaceError = require('./replace-error.js');
15
14
* @param {boolean } [options.autoStart=true]
16
15
* @param {boolean } [options.logger=null] winston-like logger
17
16
* @param {string } [options.concurrency=1]
17
+ * @param {AWSConfig } [options.awsConfig={}]
18
18
* */
19
19
20
+ /**
21
+ * @typedef {Object } AWSConfig see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html
22
+ */
20
23
function Worker ( options ) {
21
24
EventEmitter . call ( this ) ;
25
+ const awsConfig = options . awsConfig || { } ;
26
+ this . stepfunction = new AWS . StepFunctions ( awsConfig ) ;
22
27
23
28
this . autoStart = typeof ( options . autoStart ) === 'boolean' ? options . autoStart : true ;
24
29
@@ -126,7 +131,7 @@ Worker.prototype.execute = function (input, cb, heartbeat) {
126
131
Worker . prototype . succeed = function ( res ) {
127
132
const params = Object . assign ( { } , res , { output : JSON . stringify ( res . output ) } ) ;
128
133
delete params . workerName ;
129
- stepfunction . sendTaskSuccess ( params , err => {
134
+ this . stepfunction . sendTaskSuccess ( params , err => {
130
135
if ( err ) {
131
136
this . emit ( 'error' , err ) ;
132
137
} else {
@@ -146,7 +151,7 @@ Worker.prototype.fail = function (res) {
146
151
const params = Object . assign ( { } , res , { error} ) ;
147
152
delete params . workerName ;
148
153
this . logger . debug ( 'sendTaskFailure' , res . error ) ;
149
- stepfunction . sendTaskFailure ( params , err => {
154
+ this . stepfunction . sendTaskFailure ( params , err => {
150
155
if ( err ) {
151
156
this . emit ( 'error' , err ) ;
152
157
} else {
@@ -160,7 +165,7 @@ Worker.prototype.heartbeat = function (res) {
160
165
delete params . workerName ;
161
166
this . logger . debug ( 'sendTaskHeartbeat' ) ;
162
167
163
- stepfunction . sendTaskHeartbeat ( params , err => {
168
+ this . stepfunction . sendTaskHeartbeat ( params , err => {
164
169
if ( err ) {
165
170
this . emit ( 'error' , err ) ;
166
171
} else {
0 commit comments