Skip to content

Commit 8f8fb57

Browse files
author
Anton Kotenko
committed
elasticio-2070 Support flow recipe vars in mapper
1 parent b67c549 commit 8f8fb57

File tree

9 files changed

+1225
-472
lines changed

9 files changed

+1225
-472
lines changed

lib/executor.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ const { ComponentLogger } = log;
77

88
exports.TaskExec = TaskExec;
99

10-
function TaskExec({ loggerOptions } = {}) {
10+
function TaskExec({ loggerOptions, variables } = {}) {
1111
EventEmitter.call(this);
1212
this.errorCount = 0;
1313
this.logger = new ComponentLogger(loggerOptions);
14+
// copy variables to protect from outside changes;
15+
this._variables = Object.assign({}, variables || {});
1416
}
1517

1618
util.inherits(TaskExec, EventEmitter);
@@ -47,6 +49,13 @@ TaskExec.prototype.process = function process(triggerOrAction, payload, cfg, sna
4749
}
4850
};
4951

52+
/**
53+
* Returns flow variables or empty object
54+
* @returns {Object<String, String>}
55+
*/
56+
TaskExec.prototype.getFlowVariables = function getFlowVariables() {
57+
return this._variables;
58+
};
5059
const _emit = TaskExec.prototype.emit;
5160

5261
TaskExec.emit = (name, data) => {

lib/sailor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ class Sailor {
286286
threadId,
287287
messageId,
288288
parentMessageId
289-
}
289+
},
290+
variables: stepData.variables
290291
});
291292

292293
taskExec

mocha_spec/unit/executor.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const chai = require('chai');
2+
const { expect } = chai;
3+
4+
const TaskExec = require('../../lib/executor.js').TaskExec;
5+
6+
describe('Executor', () => {
7+
describe('#constructor', () => {
8+
it('should be constructable without arguments', () => {
9+
const taskexec = new TaskExec();
10+
expect(taskexec).to.be.instanceof(TaskExec);
11+
});
12+
it('should properly store variables', () => {
13+
const vars = {
14+
var1: 'val1',
15+
var2: 'val2'
16+
};
17+
const taskexec = new TaskExec({ variables: vars });
18+
expect(taskexec._variables).to.deep.equal(vars);
19+
});
20+
});
21+
describe('getVariables', () => {
22+
it('should return flow variables', () => {
23+
const vars = {
24+
var1: 'val1',
25+
var2: 'val2'
26+
};
27+
const taskexec = new TaskExec({ variables: vars });
28+
expect(taskexec.getFlowVariables()).to.deep.equal(vars);
29+
});
30+
});
31+
});

0 commit comments

Comments
 (0)