Skip to content

Commit

Permalink
Added event name
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderArce committed Nov 15, 2018
1 parent 418ebf0 commit 0572a32
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/model/Action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('Action', () => {
const params = {
name: 'testAction',
type: 'some-type',
event: 'name-event',
options: {}
}
const testAction = new Action(params)
Expand Down
4 changes: 3 additions & 1 deletion src/model/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ export default class Action {
name: string
type: string
options: any
event: string

constructor({name, type, options}: {name: string, type: string, options: any}) {
constructor({name, type, options, event}: {name: string, type: string, options: any, event: string}) {
this.name = name
this.type = type
this.options = options
this.event = event
}
}
2 changes: 2 additions & 0 deletions src/worker/ActionCreator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ describe('ActionCreator', () => {
const action = new Action({
name: 'mapper1',
type: 'mapper',
event: 'event-name',
options
})

const action2 = new Action({
name: 'mapper2',
type: 'mapper',
event: 'event-name',
options
})

Expand Down
9 changes: 6 additions & 3 deletions src/worker/ActionCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Start listening to defined rabbitmq event and execute
// the action based on type and options

import * as rabbit from 'rabbot'
import rabbit from 'rabbot'
import debug = require('debug')
import logger from '../services/logger'
import ActionExecuter from './ActionExecuter'
Expand Down Expand Up @@ -73,15 +73,18 @@ export default class ActionCreator {

// Make a Promise array and execute all the actions in serial
// fashion
executeActions (msg) {
async executeActions (msg) {
const rabbit = this.rabbit
const contents = extractMessage(msg)

let promiseChain = Promise.resolve([]).then(() => contents)

// Iterate over all actions passing the lastResult
this.event.actions.forEach((action, index) => {
const executer = new ActionExecuter(action, rabbit, this.event)
const executer = new ActionExecuter({
...action,
event: this.event.name,
}, rabbit, this.event)

const executionPromise = (lastValue, preLog, eventsLenght) => {
if (lastValue.id) {
Expand Down
8 changes: 5 additions & 3 deletions src/worker/ActionExecuter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as rabbit from 'rabbot'
import rabbit from 'rabbot'
import ActionExecuter from './ActionExecuter'
import Action from '../model/Action'
import Event from '../model/Event'
Expand All @@ -11,7 +11,8 @@ describe('ActionExecuter', () => {
options: {
target: 'test',
targetRoute: 'someroute'
}
},
event: 'event-name',
})

const actionExecuter = new ActionExecuter(action, rabbit, new Event({
Expand Down Expand Up @@ -43,7 +44,8 @@ describe('ActionExecuter', () => {
field: 'test',
operation: 'defined'
}
}
},
event: 'event-name',
})

const actionExecuter = new ActionExecuter(action, rabbit, new Event({name: 'test', eventName: 'test', route: 'test', actions: []}))
Expand Down
15 changes: 10 additions & 5 deletions src/worker/execution-plugins/conditional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('conditional', () => {
checkValue: 'test'
}
]
}
},
event: 'event-name',
})
const conditionalPlugin = new ConditionalPlugin(msg, action, '')

Expand All @@ -34,7 +35,8 @@ describe('conditional', () => {
checkValue: 'world'
}
]
}
},
event: 'event-name',
})
const passingConditionalPlugin = new ConditionalPlugin(msg, passingAction, '')

Expand All @@ -55,7 +57,8 @@ describe('conditional', () => {
checkValue: 'world'
}
]
}
},
event: 'event-name',
})
const passingConditionalPlugin = new ConditionalPlugin(msg, passingAction, '')

Expand All @@ -80,7 +83,8 @@ describe('conditional', () => {
operation: 'defined'
}
]
}
},
event: 'event-name',
})
const passingConditionalPlugin = new ConditionalPlugin(msg, passingAction, '')

Expand Down Expand Up @@ -109,7 +113,8 @@ describe('conditional', () => {
operation: 'defined'
}
]
}
},
event: 'event-name',
})

const nonPassingConditionalPlugin = new ConditionalPlugin(msg, nonPassingAction, '')
Expand Down
6 changes: 4 additions & 2 deletions src/worker/execution-plugins/http.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('http', () => {
url: 'http://localhost:3000/{{ hello }}',
method: 'GET',
merge: true
}
},
event: 'name-event',
})
const httpPlugin = new HttpPlugin(msg, action, 'test')
const mock = new MockAdapter(axios)
Expand Down Expand Up @@ -64,7 +65,8 @@ describe('http', () => {
method: 'GET',
merge: true,
mergeTarget: 'response'
}
},
event: 'name-event',
})
const httpPlugin = new HttpPlugin(msg, action, 'test')

Expand Down
3 changes: 2 additions & 1 deletion src/worker/execution-plugins/log.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ describe('log', () => {
const action = new Action({
name: 'log',
type: 'log',
options: {}
options: {},
event: 'event-name',
})

const logPlugin = new LogPlugin({test: 'value', test2: 'value2'}, action, 'preLog')
Expand Down
3 changes: 2 additions & 1 deletion src/worker/execution-plugins/prev2task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ describe('prev2task', () => {
options: {
target: 'some-queue',
targetRoute: 'some-route'
}
},
event: 'event-name',
})
const rabbit = {
publish: () => Promise.resolve({})
Expand Down
3 changes: 2 additions & 1 deletion src/worker/execution-plugins/telegram.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('telegram', () => {
options: {
chatId: '1324',
template: 'Test'
}
},
event: 'event-name',
})

it('should allow to be initialized with passed configurations', () => {
Expand Down

0 comments on commit 0572a32

Please sign in to comment.