@@ -2,7 +2,6 @@ const EventEmitter = require('events').EventEmitter;
22const util = require ( 'util' ) ;
33const AWS = require ( 'aws-sdk' ) ;
44
5- const stepfunction = new AWS . StepFunctions ( ) ;
65const Pooler = require ( './pooler.js' ) ;
76const replaceError = require ( './replace-error.js' ) ;
87
@@ -15,10 +14,16 @@ const replaceError = require('./replace-error.js');
1514* @param {boolean } [options.autoStart=true]
1615* @param {boolean } [options.logger=null] winston-like logger
1716* @param {string } [options.concurrency=1]
17+ * @param {AWSConfig } [options.awsConfig={}]
1818* */
1919
20+ /**
21+ * @typedef {Object } AWSConfig see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html
22+ */
2023function Worker ( options ) {
2124 EventEmitter . call ( this ) ;
25+ const awsConfig = options . awsConfig || { } ;
26+ this . stepfunction = new AWS . StepFunctions ( awsConfig ) ;
2227
2328 this . autoStart = typeof ( options . autoStart ) === 'boolean' ? options . autoStart : true ;
2429
@@ -126,7 +131,7 @@ Worker.prototype.execute = function (input, cb, heartbeat) {
126131Worker . prototype . succeed = function ( res ) {
127132 const params = Object . assign ( { } , res , { output : JSON . stringify ( res . output ) } ) ;
128133 delete params . workerName ;
129- stepfunction . sendTaskSuccess ( params , err => {
134+ this . stepfunction . sendTaskSuccess ( params , err => {
130135 if ( err ) {
131136 this . emit ( 'error' , err ) ;
132137 } else {
@@ -146,7 +151,7 @@ Worker.prototype.fail = function (res) {
146151 const params = Object . assign ( { } , res , { error} ) ;
147152 delete params . workerName ;
148153 this . logger . debug ( 'sendTaskFailure' , res . error ) ;
149- stepfunction . sendTaskFailure ( params , err => {
154+ this . stepfunction . sendTaskFailure ( params , err => {
150155 if ( err ) {
151156 this . emit ( 'error' , err ) ;
152157 } else {
@@ -160,7 +165,7 @@ Worker.prototype.heartbeat = function (res) {
160165 delete params . workerName ;
161166 this . logger . debug ( 'sendTaskHeartbeat' ) ;
162167
163- stepfunction . sendTaskHeartbeat ( params , err => {
168+ this . stepfunction . sendTaskHeartbeat ( params , err => {
164169 if ( err ) {
165170 this . emit ( 'error' , err ) ;
166171 } else {
0 commit comments