2021-05-25 13:27:45 +00:00
|
|
|
let sendPings
|
|
|
|
const redis = require('@overleaf/redis-wrapper')
|
|
|
|
const rclient1 = redis.createClient({
|
|
|
|
cluster: [
|
|
|
|
{
|
|
|
|
port: '7000',
|
2024-04-25 12:56:00 +00:00
|
|
|
host: '127.0.0.1',
|
2021-07-13 11:04:42 +00:00
|
|
|
},
|
|
|
|
],
|
2021-05-25 13:27:45 +00:00
|
|
|
})
|
2017-05-04 10:14:17 +00:00
|
|
|
|
2021-05-25 13:27:45 +00:00
|
|
|
const rclient2 = redis.createClient({
|
|
|
|
cluster: [
|
|
|
|
{
|
|
|
|
port: '7000',
|
2024-04-25 12:56:00 +00:00
|
|
|
host: '127.0.0.1',
|
2021-07-13 11:04:42 +00:00
|
|
|
},
|
|
|
|
],
|
2021-05-25 13:27:45 +00:00
|
|
|
})
|
2017-05-04 10:14:17 +00:00
|
|
|
|
2021-05-25 13:27:45 +00:00
|
|
|
let counter = 0
|
|
|
|
const sendPing = function (cb) {
|
|
|
|
if (cb == null) {
|
|
|
|
cb = function () {}
|
|
|
|
}
|
2021-07-13 11:04:42 +00:00
|
|
|
return rclient1.publish('test-pubsub', counter, error => {
|
2021-05-25 13:32:03 +00:00
|
|
|
if (error) {
|
2021-05-25 13:27:45 +00:00
|
|
|
console.error('[SENDING ERROR]', error.message)
|
|
|
|
}
|
|
|
|
if (error == null) {
|
|
|
|
counter += 1
|
|
|
|
}
|
|
|
|
return cb()
|
|
|
|
})
|
|
|
|
}
|
2017-05-04 10:14:17 +00:00
|
|
|
|
2021-05-25 13:27:45 +00:00
|
|
|
let previous = null
|
|
|
|
rclient2.subscribe('test-pubsub')
|
|
|
|
rclient2.on('message', (channel, value) => {
|
|
|
|
value = parseInt(value, 10)
|
|
|
|
if (value % 10 === 0) {
|
|
|
|
console.log('.')
|
|
|
|
}
|
|
|
|
if (previous != null && value !== previous + 1) {
|
|
|
|
console.error(
|
|
|
|
'[RECEIVING ERROR]',
|
|
|
|
`Counter not in order. Got ${value}, expected ${previous + 1}`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return (previous = value)
|
|
|
|
})
|
2017-05-04 10:14:17 +00:00
|
|
|
|
2021-05-25 13:27:45 +00:00
|
|
|
const PING_DELAY = 100
|
|
|
|
;(sendPings = () => sendPing(() => setTimeout(sendPings, PING_DELAY)))()
|