fix: Improve graceful shutdown
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
"build:webpack": "webpack --config webpack.config.prod.js",
|
||||
"build": "yarn clean && yarn build:webpack && yarn build:i18n && yarn build:server",
|
||||
"start": "node ./build/server/index.js",
|
||||
"dev": "yarn concurrently --kill-others -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=websockets,admin,web,worker\" \"node build/server/index.js --services=collaboration --port=4000\"",
|
||||
"dev": "yarn concurrently -n api,collaboration -c \"blue,magenta\" \"node --inspect=0.0.0.0 build/server/index.js --services=websockets,admin,web,worker\" \"node build/server/index.js --services=collaboration --port=4000\"",
|
||||
"dev:watch": "nodemon --exec \"yarn build:server && yarn build:i18n && yarn dev\" -e js --ignore build/ --ignore app/ --ignore flow-typed/",
|
||||
"lint": "eslint app server shared",
|
||||
"deploy": "git push heroku master",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import Metrics from "../logging/metrics";
|
||||
|
||||
export default class Tracing {
|
||||
async onCreateDocument({
|
||||
onCreateDocument({
|
||||
documentName,
|
||||
instance,
|
||||
}: {
|
||||
@@ -17,11 +17,11 @@ export default class Tracing {
|
||||
);
|
||||
}
|
||||
|
||||
async onAuthenticationFailed({ documentName }: { documentName: string }) {
|
||||
onAuthenticationFailed({ documentName }: { documentName: string }) {
|
||||
Metrics.increment("collaboration.authentication_failed", { documentName });
|
||||
}
|
||||
|
||||
async onConnect({
|
||||
onConnect({
|
||||
documentName,
|
||||
instance,
|
||||
}: {
|
||||
@@ -35,7 +35,7 @@ export default class Tracing {
|
||||
);
|
||||
}
|
||||
|
||||
async onDisconnect({
|
||||
onDisconnect({
|
||||
documentName,
|
||||
instance,
|
||||
}: {
|
||||
@@ -54,7 +54,12 @@ export default class Tracing {
|
||||
);
|
||||
}
|
||||
|
||||
async onChange({ documentName }: { documentName: string }) {
|
||||
onChange({ documentName }: { documentName: string }) {
|
||||
Metrics.increment("collaboration.change", { documentName });
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
Metrics.gaugePerInstance("collaboration.connections_count", 0);
|
||||
Metrics.gaugePerInstance("collaboration.documents_count", 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,8 @@ async function start(id: string, disconnect: () => void) {
|
||||
|
||||
function shutdown() {
|
||||
Logger.info("lifecycle", "Stopping server");
|
||||
|
||||
server.emit("shutdown");
|
||||
server.stop(disconnect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,8 @@ export default function init(app: Koa, server: http.Server) {
|
||||
app.use(websocket());
|
||||
app.use(router.routes());
|
||||
app.use(router.allowedMethods());
|
||||
|
||||
server.on("shutdown", () => {
|
||||
hocuspocus.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ export default function init(app: Koa, server: http.Server) {
|
||||
cookie: false,
|
||||
});
|
||||
|
||||
server.on("shutdown", () => {
|
||||
Metrics.gaugePerInstance("websockets.count", 0);
|
||||
});
|
||||
|
||||
io.adapter(
|
||||
socketRedisAdapter({
|
||||
pubClient: client,
|
||||
|
||||
Reference in New Issue
Block a user