11const EventEmitter = require ( 'events' ) . EventEmitter ;
22const util = require ( 'util' ) ;
33const AWS = require ( 'aws-sdk' ) ;
4+ const parser = require ( 'aws-arn-parser' ) ;
45
56const Pooler = require ( './pooler.js' ) ;
67const replaceError = require ( './replace-error.js' ) ;
@@ -28,8 +29,7 @@ function Worker(options) {
2829 this . autoStart = typeof ( options . autoStart ) === 'boolean' ? options . autoStart : true ;
2930
3031 if ( ! options . activityArn ) {
31- this . emit ( 'error' , new Error ( 'activityArn is mandatory inside Worker' ) ) ;
32- return ;
32+ throw ( new Error ( 'activityArn is mandatory inside Worker' ) ) ;
3333 }
3434
3535 this . concurrency = typeof ( options . concurrency ) === 'number' ? options . concurrency : 1 ;
@@ -49,6 +49,12 @@ function Worker(options) {
4949 throw ( new TypeError ( 'worker does not define any function' ) ) ;
5050 }
5151
52+ const { region} = parser ( options . activityArn ) ;
53+
54+ if ( typeof ( region ) === 'string' && ( this . stepfunction . config . region !== region ) ) {
55+ throw ( new Error ( `activity ARN region (${ region } ) should match with AWS Region (${ this . stepfunction . config . region } )` ) ) ;
56+ }
57+
5258 if ( this . autoStart ) {
5359 setImmediate ( ( ) => {
5460 this . start ( ( ) => {
@@ -131,9 +137,10 @@ Worker.prototype.execute = function (input, cb, heartbeat) {
131137Worker . prototype . succeed = function ( res ) {
132138 const params = Object . assign ( { } , res , { output : JSON . stringify ( res . output ) } ) ;
133139 delete params . workerName ;
140+ delete params . input ;
134141 this . stepfunction . sendTaskSuccess ( params , err => {
135142 if ( err ) {
136- this . emit ( 'error' , err ) ;
143+ this . emit ( 'error' , { err, input : res . input } ) ;
137144 } else {
138145 this . emit ( 'success' , res ) ;
139146 }
@@ -150,10 +157,11 @@ Worker.prototype.fail = function (res) {
150157 }
151158 const params = Object . assign ( { } , res , { error} ) ;
152159 delete params . workerName ;
160+ delete params . input ;
153161 this . logger . debug ( 'sendTaskFailure' , res . error ) ;
154162 this . stepfunction . sendTaskFailure ( params , err => {
155163 if ( err ) {
156- this . emit ( 'error' , err ) ;
164+ this . emit ( 'error' , { err, input : res . input } ) ;
157165 } else {
158166 this . emit ( 'failure' , res ) ;
159167 }
@@ -163,11 +171,12 @@ Worker.prototype.fail = function (res) {
163171Worker . prototype . heartbeat = function ( res ) {
164172 const params = Object . assign ( { } , res ) ;
165173 delete params . workerName ;
174+ delete params . input ;
166175 this . logger . debug ( 'sendTaskHeartbeat' ) ;
167176
168177 this . stepfunction . sendTaskHeartbeat ( params , err => {
169178 if ( err ) {
170- this . emit ( 'error' , err ) ;
179+ this . emit ( 'error' , { err, input : res . input } ) ;
171180 } else {
172181 this . emit ( 'heartbeat' , res ) ;
173182 }
0 commit comments