diff --git a/src/worker/action-creator.js b/src/worker/action-creator.js index a7100af..d529019 100644 --- a/src/worker/action-creator.js +++ b/src/worker/action-creator.js @@ -36,7 +36,7 @@ module.exports = class ActionCreator { } this.rabbit = rabbit this.event = event - this.preLog = event.name + ':' + this.preLog = event.name + ' >' } createHandler() { @@ -77,7 +77,7 @@ module.exports = class ActionCreator { // Iterate over all actions passing the lastResult this.event.actions.forEach((action, index) => { - const executer = new ActionExecuter(action, rabbit) + const executer = new ActionExecuter(action, rabbit, this.event) const executionPromise = function (lastValue, preLog, eventsLenght) { preLog = preLog + ' [' + lastValue.id + ']:' diff --git a/src/worker/action-executer.js b/src/worker/action-executer.js index a8055d4..100b389 100644 --- a/src/worker/action-executer.js +++ b/src/worker/action-executer.js @@ -7,10 +7,12 @@ const ObjectTransformerPlugin = require('./execution-plugins/object-transformer- const debug = require('debug')('action-executer') module.exports = class ActionExecuter { - constructor(action, rabbit) { + constructor(action, rabbit, event) { debug('action executer action received: %j', action) this.action = action this.rabbit = rabbit + this.event = event + this.preLog = event.name + ' >' } // Instantiate the proper plugin with proper parameters and execute it @@ -26,35 +28,40 @@ module.exports = class ActionExecuter { switch (this.action.type) { case 'log': executionPlugin = new LogPlugin( - prevMessage, - this.action - ) + prevMessage, + this.action, + this.preLog + ) break case 'mapper': case 'obj-transformer': executionPlugin = new ObjectTransformerPlugin( - prevMessage, - this.action - ) + prevMessage, + this.action, + this.preLog + ) break case 'http': executionPlugin = new HttpPlugin( - prevMessage, - this.action - ) + prevMessage, + this.action, + this.preLog + ) break case 'conditional': executionPlugin = new ConditionalPlugin( - prevMessage, - this.action - ) + prevMessage, + this.action, + this.preLog + ) break case 'event2task': case 'prev2task': executionPlugin = new Event2TaskPlugin( prevMessage, this.action, - this.rabbit + this.rabbit, + this.preLog ) break default: diff --git a/src/worker/action-executer.spec.js b/src/worker/action-executer.spec.js index 05f093b..d7a5392 100644 --- a/src/worker/action-executer.spec.js +++ b/src/worker/action-executer.spec.js @@ -17,7 +17,7 @@ describe('ActionExecuter', () => { expect(action.isErrors()).to.be.false - const actionExecuter = new ActionExecuter(action, rabbit) + const actionExecuter = new ActionExecuter(action, rabbit, {name: 'test'}) const msg = { body: { diff --git a/src/worker/execution-plugins/conditional-plugin.js b/src/worker/execution-plugins/conditional-plugin.js index 13b33b3..52d2448 100644 --- a/src/worker/execution-plugins/conditional-plugin.js +++ b/src/worker/execution-plugins/conditional-plugin.js @@ -52,10 +52,10 @@ const PluginOptionsSchema = new SchemaObject({ }) module.exports = class ConditionalPlugin { - constructor(msg, action) { + constructor(msg, action, preLog) { this.msg = msg this.action = action - this.preLog = action.name + '[ ' + msg.id + ' ]' + this.preLog = preLog + ' > ' + action.name this.parsedMessage = flattenObject( this.msg ) diff --git a/src/worker/execution-plugins/event2task-plugin.js b/src/worker/execution-plugins/event2task-plugin.js index 89a8767..c4bafb5 100644 --- a/src/worker/execution-plugins/event2task-plugin.js +++ b/src/worker/execution-plugins/event2task-plugin.js @@ -15,7 +15,7 @@ const PluginOptionsSchema = new SchemaObject({ }) module.exports = class Event2TaskPlugin { - constructor(msg, action, rabbit) { + constructor(msg, action, rabbit, preLog) { if (!rabbit) { throw new Error('You must provide a rabbitmq instance') } @@ -28,6 +28,7 @@ module.exports = class Event2TaskPlugin { this.msg = msg this.action = action this.rabbit = rabbit + this.preLog = preLog + ' > ' + action.name } execute(callback) { @@ -46,10 +47,10 @@ module.exports = class Event2TaskPlugin { body: payload, replyTimeout: 3000 }).then(() => { - logger.info(this.action.name, ': event2task executed') + logger.info(this.preLog, ': event2task executed') return callback(null, this.msg) }, (err) => { - logger.info(this.action.name, ': event2task failed') + logger.info(this.preLog, ': event2task failed') return callback(new Error('Error publishing to the quque', err)) }) } diff --git a/src/worker/execution-plugins/http-plugin.js b/src/worker/execution-plugins/http-plugin.js index ded214a..9d241d2 100644 --- a/src/worker/execution-plugins/http-plugin.js +++ b/src/worker/execution-plugins/http-plugin.js @@ -16,13 +16,14 @@ const PluginOptionsSchema = new SchemaObject({ }) module.exports = class HttpPlugin { - constructor(msg, action) { + constructor(msg, action, preLog) { this.msg = msg this.options = new PluginOptionsSchema(action.options) if (this.options.isErrors()) { throw new Error('The options provided are not valid '+ JSON.stringify(this.options.getErrors())) } + this.preLog = preLog + ' > ' + action.name } renderUrl() { diff --git a/src/worker/execution-plugins/log-plugin.js b/src/worker/execution-plugins/log-plugin.js index e5d5979..b9292dd 100644 --- a/src/worker/execution-plugins/log-plugin.js +++ b/src/worker/execution-plugins/log-plugin.js @@ -1,13 +1,14 @@ const { logger } = require('../../utils/logger') module.exports = class LogPlugin { - constructor(msg, action) { + constructor(msg, action, preLog) { this.msg = msg this.action = action + this.preLog = preLog + ' > ' + action.name } execute(callback) { - logger.info(this.action.name, ': ', this.msg) + logger.info(this.preLog, this.msg) return callback(null, this.msg) } } diff --git a/src/worker/execution-plugins/object-transformer-plugin.js b/src/worker/execution-plugins/object-transformer-plugin.js index 16d5497..c8ab144 100644 --- a/src/worker/execution-plugins/object-transformer-plugin.js +++ b/src/worker/execution-plugins/object-transformer-plugin.js @@ -16,7 +16,7 @@ const PluginOptionsSchema = new SchemaObject({ }) module.exports = class ObjectTransformerPlugin { - constructor(msg, action) { + constructor(msg, action, preLog) { this.msg = msg this.action = action debug('received next msg: %j', this.msg) @@ -34,6 +34,8 @@ module.exports = class ObjectTransformerPlugin { if (this.options.isErrors()) { throw new Error('The options provided are not valid '+ JSON.stringify(this.options.getErrors())) } + + this.preLog = preLog + ' > ' + action.name } execute(callback) { @@ -49,7 +51,7 @@ module.exports = class ObjectTransformerPlugin { } debug('Result mapped object is %j', transformedObj) - logger.info(this.action.name, ': Object mapping applied') + logger.info(this.preLog, 'Object mapping applied') return callback(null, transformedObj) }