mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
f7275a6c4b
Upgrade logger and metrics in all services GitOrigin-RevId: 2baf63eeeab77fb3559cf763ddacfbf4b745cd0b
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/* eslint-disable
|
|
camelcase,
|
|
*/
|
|
const WebsocketLoadBalancer = require('./WebsocketLoadBalancer')
|
|
const DrainManager = require('./DrainManager')
|
|
const logger = require('@overleaf/logger')
|
|
|
|
module.exports = {
|
|
sendMessage(req, res) {
|
|
logger.debug({ message: req.params.message }, 'sending message')
|
|
if (Array.isArray(req.body)) {
|
|
for (const payload of req.body) {
|
|
WebsocketLoadBalancer.emitToRoom(
|
|
req.params.project_id,
|
|
req.params.message,
|
|
payload
|
|
)
|
|
}
|
|
} else {
|
|
WebsocketLoadBalancer.emitToRoom(
|
|
req.params.project_id,
|
|
req.params.message,
|
|
req.body
|
|
)
|
|
}
|
|
res.sendStatus(204)
|
|
},
|
|
|
|
startDrain(req, res) {
|
|
const io = req.app.get('io')
|
|
let rate = req.query.rate || '4'
|
|
rate = parseFloat(rate) || 0
|
|
logger.info({ rate }, 'setting client drain rate')
|
|
DrainManager.startDrain(io, rate)
|
|
res.sendStatus(204)
|
|
},
|
|
|
|
disconnectClient(req, res, next) {
|
|
const io = req.app.get('io')
|
|
const { client_id } = req.params
|
|
const client = io.sockets.sockets[client_id]
|
|
|
|
if (!client) {
|
|
logger.debug({ client_id }, 'api: client already disconnected')
|
|
res.sendStatus(404)
|
|
return
|
|
}
|
|
logger.info({ client_id }, 'api: requesting client disconnect')
|
|
client.on('disconnect', () => res.sendStatus(204))
|
|
client.disconnect()
|
|
},
|
|
}
|