-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
37 lines (34 loc) · 936 Bytes
/
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
const amqp = require('amqplib')
const redis = require('redis')
const env = require('./lib/env')
const { parseRegistryUrl, checkFollower, startChanges } = require('./lib/follow')
;(async () => {
const conn = await amqp.connect(env.AMQP_URL)
const channel = await conn.createChannel()
await channel.assertQueue(env.QUEUE_NAME, {
maxPriority: 5
})
const client = redis.createClient(env.REDIS_URL)
env.REGISTRY_URLS.forEach(registryUrl => {
const registry = parseRegistryUrl(registryUrl)
const start = startChanges.bind(null, {
channel,
client,
registry
}, (err, changes) => {
if (err) {
setTimeout(start, 1000)
}
const check = checkFollower.bind(null, {
registry,
changes,
client
}, restart => {
if (restart) return start()
setTimeout(check, 30000)
})
setTimeout(check, 30000)
})
start()
})
})()