Skip to content

Commit 421ed2a

Browse files
committed
feat: adding awsConfig
1 parent 89d3f9b commit 421ed2a

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/pooler.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const EventEmitter = require('events').EventEmitter;
33
const AWS = require('aws-sdk');
44
const Task = require('./task.js');
55

6-
const stepfunction = new AWS.StepFunctions();
7-
86
/**
97
* @class Pooler
108
* @param {object} options
@@ -82,7 +80,7 @@ Pooler.prototype.pool = function () {
8280

8381
Pooler.prototype.getActivityTask = function () {
8482
this.logger.debug(this.workerName + ' getActivityTask ' + this.activityArn);
85-
this._request = stepfunction.getActivityTask({
83+
this._request = this.worker.stepfunction.getActivityTask({
8684
activityArn: this.activityArn,
8785
workerName: this.workerName
8886
}, (err, data) => {

lib/worker.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const EventEmitter = require('events').EventEmitter;
22
const util = require('util');
33
const AWS = require('aws-sdk');
44

5-
const stepfunction = new AWS.StepFunctions();
65
const Pooler = require('./pooler.js');
76
const 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+
*/
2023
function 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) {
126131
Worker.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

Comments
 (0)