-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (65 loc) · 1.84 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @file index
* @author Jim Bulkowski <[email protected]>
* @project Pomegranate-task-utilities
* @license MIT {@link http://opensource.org/licenses/MIT}
*/
'use strict';
const WriterFacade = require('./lib/TaskWriter/WriterFacade')
const _ = require('lodash')
/**
*
* @module index
*/
exports.options = {
loadRpcReply: false,
queues: [{
propName: 'local',
queueName: 'my.task.queue',
type: 'queue' ,
RPC: { enabled: false, defaultTimeout: 1000 },
msgOptions: {persistent: true},
queueOptions: {}
}],
exchanges: [
{
propName: 'fanout',
exchangeName: 'my.fanout.exchange',
type: 'fanout',
msgOptions: {persistent: true},
exchangeOptions: {}
}
]
}
exports.metadata = {
frameworkVersion: 6,
name: 'TaskUtilities',
type: 'dynamic',
optional: ['RabbitConnection']
}
exports.plugin = {
load: function(Options, Logger, Injector, inject, loaded) {
let plugins = [
{param: 'TaskBuilder', load: require('./lib/TaskBuilder')},
{param: 'TaskValidator', load: require('./lib/TaskValidator')}
]
let RabbitConnection = Injector.inject('RabbitConnection')
if(RabbitConnection && Options.queues && Options.queues.length){
return RabbitConnection.createChannel()
.then((channel)=> {
if(Options.loadRpcReply||_.some(Options.queues, {RPC: {enabled: true}})){
Logger.log("RPC enabled queues found, will load - 'RpcReply'.")
let rpcr = require('./lib/RpcReply')
plugins.push({param: 'RpcReply', load: rpcr(channel)})
}
let wf = new WriterFacade(Options.queues,Options.exchanges, channel, Logger)
plugins.push({param: 'AddTask', load: wf})
return wf.initialize()
})
.then(function(dynamics){
return plugins
})
}
return plugins
}
}