forked from HubSpot/BuckyServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectors.coffee
40 lines (31 loc) · 994 Bytes
/
collectors.coffee
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
Q = require 'q'
_ = require 'underscore'
load = require "../lib/load"
modules = require("config").modules
module.exports = ({app, logger, config}, next) ->
collectorHandler = (collectors) ->
return (req, res) ->
res.send(204, '')
for coll in collectors
coll(req.body, {req, res})
logger.log "Loading collectors: #{ modules.collectors.join(', ') }"
collectors = {}
collPromises = []
_.map modules.collectors, (name) ->
promise = load name, {logger, config, app}
promise.then (ret) ->
logger.log "Collector #{ name } ready"
collectors[name] = ret
collPromises.push promise
Q.all(collPromises).done ->
handlers = {}
for name, collector of collectors
for path, handler of collector
if not handlers[path]?
handlers[path] = [handler]
else
handlers[path].push handler
collector = {}
for path, hls of handlers
collector[path] = collectorHandler(hls)
next collector