Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/pooler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const util = require('util');
const EventEmitter = require('events').EventEmitter;
const AWS = require('aws-sdk');
const Task = require('./task.js');

const stepfunction = new AWS.StepFunctions();

/**
* @class Pooler
* @param {object} options
Expand Down Expand Up @@ -82,7 +79,7 @@ Pooler.prototype.pool = function () {

Pooler.prototype.getActivityTask = function () {
this.logger.debug(this.workerName + ' getActivityTask ' + this.activityArn);
this._request = stepfunction.getActivityTask({
this._request = this.worker.stepfunction.getActivityTask({
activityArn: this.activityArn,
workerName: this.workerName
}, (err, data) => {
Expand Down
13 changes: 9 additions & 4 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const EventEmitter = require('events').EventEmitter;
const util = require('util');
const AWS = require('aws-sdk');

const stepfunction = new AWS.StepFunctions();
const Pooler = require('./pooler.js');
const replaceError = require('./replace-error.js');

Expand All @@ -15,10 +14,16 @@ const replaceError = require('./replace-error.js');
* @param {boolean} [options.autoStart=true]
* @param {boolean} [options.logger=null] winston-like logger
* @param {string} [options.concurrency=1]
* @param {AWSConfig} [options.awsConfig={}]
* */

/**
* @typedef {Object} AWSConfig see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html
*/
function Worker(options) {
EventEmitter.call(this);
const awsConfig = options.awsConfig || {};
this.stepfunction = new AWS.StepFunctions(awsConfig);

this.autoStart = typeof (options.autoStart) === 'boolean' ? options.autoStart : true;

Expand Down Expand Up @@ -126,7 +131,7 @@ Worker.prototype.execute = function (input, cb, heartbeat) {
Worker.prototype.succeed = function (res) {
const params = Object.assign({}, res, {output: JSON.stringify(res.output)});
delete params.workerName;
stepfunction.sendTaskSuccess(params, err => {
this.stepfunction.sendTaskSuccess(params, err => {
if (err) {
this.emit('error', err);
} else {
Expand All @@ -146,7 +151,7 @@ Worker.prototype.fail = function (res) {
const params = Object.assign({}, res, {error});
delete params.workerName;
this.logger.debug('sendTaskFailure', res.error);
stepfunction.sendTaskFailure(params, err => {
this.stepfunction.sendTaskFailure(params, err => {
if (err) {
this.emit('error', err);
} else {
Expand All @@ -160,7 +165,7 @@ Worker.prototype.heartbeat = function (res) {
delete params.workerName;
this.logger.debug('sendTaskHeartbeat');

stepfunction.sendTaskHeartbeat(params, err => {
this.stepfunction.sendTaskHeartbeat(params, err => {
if (err) {
this.emit('error', err);
} else {
Expand Down