blob: 655c61ff272cc61a47ddda1730d6cfa6667917f7 (
plain) (
blame)
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
|
'use strict'
let l
export default l = async (node, consul, log, notify) => {
const watch = consul.watch({ method: consul.catalog.node.services, options: {node: node}})
const extract_tags = data =>
data ?
Object
.keys(data.Services)
.map(k => data.Services[k].Tags)
.reduce((acc, v) => [...acc, ...v], []) :
[]
watch.on('error', err => {
console.error('error', err)
})
watch.on('change', async (data, res) => {
try {
const tags = extract_tags(data)
log(`[consul] new update, detected ${tags.length} tags`)
await notify(tags)
} catch(e) {
console.error('failed to notify target', e)
}
})
log('[consul] initialized')
}
|