From 26e903f384e8fdfcea921579a80da405ac051a91 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 15 Feb 2019 15:23:59 +0000 Subject: [PATCH] setup continualPubsubTraffic this keeps the pub sub channel ticking along happily --- services/real-time/app.coffee | 25 +++++++++++++++++++ .../coffee/DocumentUpdaterController.coffee | 2 ++ .../app/coffee/WebsocketLoadBalancer.coffee | 2 ++ .../real-time/config/settings.defaults.coffee | 2 ++ 4 files changed, 31 insertions(+) diff --git a/services/real-time/app.coffee b/services/real-time/app.coffee index 2661ce8430..89f0cdfb36 100644 --- a/services/real-time/app.coffee +++ b/services/real-time/app.coffee @@ -1,6 +1,7 @@ Metrics = require("metrics-sharelatex") Settings = require "settings-sharelatex" Metrics.initialize(Settings.appName or "real-time") +async = require("async") logger = require "logger-sharelatex" logger.initialize("real-time") @@ -115,3 +116,27 @@ if Settings.forceDrainMsDelay? logger.log signal: signal, "received interrupt, cleaning up" shutdownCleanly(signal) forceDrain() + + + +if Settings.continualPubsubTraffic + console.log "continualPubsubTraffic enabled" + + pubSubClient = redis.createClient(Settings.redis.documentupdater) + + publishJob = (channel, cb)-> + json = JSON.stringify({health_check:true, date: new Date().toString()}) + logger.debug {channel:channel}, "sending pub to keep connection alive" + pubSubClient.publish channel, json, (err)-> + if err? + logger.err {err, channel}, "error publishing pubsub traffic to redis" + cb(err) + + runPubSubTraffic = -> + async.map ["applied-ops", "editor-events"], publishJob, (err)-> + setTimeout(runPubSubTraffic, 1000 * 60) + + runPubSubTraffic() + + + diff --git a/services/real-time/app/coffee/DocumentUpdaterController.coffee b/services/real-time/app/coffee/DocumentUpdaterController.coffee index 451dc812bc..8396be263a 100644 --- a/services/real-time/app/coffee/DocumentUpdaterController.coffee +++ b/services/real-time/app/coffee/DocumentUpdaterController.coffee @@ -24,6 +24,8 @@ module.exports = DocumentUpdaterController = DocumentUpdaterController._applyUpdateFromDocumentUpdater(io, message.doc_id, message.op) else if message.error? DocumentUpdaterController._processErrorFromDocumentUpdater(io, message.doc_id, message.error, message) + else if message.health_check? + logger.debug {message}, "got health check message in applied ops channel" _applyUpdateFromDocumentUpdater: (io, doc_id, update) -> for client in io.sockets.clients(doc_id) diff --git a/services/real-time/app/coffee/WebsocketLoadBalancer.coffee b/services/real-time/app/coffee/WebsocketLoadBalancer.coffee index 56ce8e5d30..c30a3d3e85 100644 --- a/services/real-time/app/coffee/WebsocketLoadBalancer.coffee +++ b/services/real-time/app/coffee/WebsocketLoadBalancer.coffee @@ -37,4 +37,6 @@ module.exports = WebsocketLoadBalancer = io.sockets.emit(message.message, message.payload...) else if message.room_id? io.sockets.in(message.room_id).emit(message.message, message.payload...) + else if message.health_check? + logger.debug {message}, "got health check message in editor events channel" diff --git a/services/real-time/config/settings.defaults.coffee b/services/real-time/config/settings.defaults.coffee index 93a980931e..0fe6fa7be1 100644 --- a/services/real-time/config/settings.defaults.coffee +++ b/services/real-time/config/settings.defaults.coffee @@ -44,6 +44,8 @@ settings = forceDrainMsDelay: process.env['FORCE_DRAIN_MS_DELAY'] or false + continualPubsubTraffic: process.env['CONTINUAL_PUBSUB_TRAFFIC'] or false + # console.log settings.redis module.exports = settings \ No newline at end of file