0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Add a metric when shutting down in-flight requests takes more than 15 seconds

refs: https://github.com/TryGhost/DevOps/issues/64
This commit is contained in:
Sam Lord 2023-10-04 15:07:29 +01:00 committed by Sam Lord
parent 7b3a0c6863
commit 45f704ce86

View file

@ -4,6 +4,7 @@ const debug = require('@tryghost/debug')('server');
const errors = require('@tryghost/errors');
const tpl = require('@tryghost/tpl');
const logging = require('@tryghost/logging');
const metrics = require('@tryghost/metrics');
const notify = require('./notify');
const moment = require('moment');
const stoppable = require('stoppable');
@ -169,8 +170,16 @@ class GhostServer {
try {
// If we never fully started, there's nothing to stop
if (this.httpServer && this.httpServer.listening) {
// Time how long it takes to close all in-flight requests
const startTime = Date.now();
// We stop the server first so that no new long running requests or processes can be started
await this._stopServer();
const shutdownDuration = Date.now() - startTime;
if (shutdownDuration > 15000) {
metrics.metric('long-shutdown', shutdownDuration);
}
}
// Do all of the cleanup tasks
await this._cleanup();