From 9f291b2d1025711f5bc507b97178aae42c9fa99f Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 18 Aug 2020 15:36:21 +0100 Subject: [PATCH] Improved testmode logging of shutdown status - testmode allows us to test Ghost's behaviour with long running requests and jobs - moved all the testmode logging to only happen if Ghost starts successfully to make it clearer what is happening - added a (currently very dirty) bit of code to fetch the jobService and output the queue status giving us a similar output for both open connections and jobs - all of this allows for debugging exactly what Ghost is doing whilst it is processing a shutdown request --- core/server/ghost-server.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/core/server/ghost-server.js b/core/server/ghost-server.js index b4d59de273..861c3a8d10 100644 --- a/core/server/ghost-server.js +++ b/core/server/ghost-server.js @@ -107,6 +107,26 @@ class GhostServer { debug('...Started'); self._logStartMessages(); + // Debug logs output in testmode only + if (config.get('server:testmode')) { + // This is horrible and very temporary + const jobService = require('./services/jobs'); + + // Output how many connections are open every 5 seconds + const connectionInterval = setInterval(() => self.httpServer.getConnections( + (err, connections) => logging.warn(`${connections} connections currently open`) + ), 5000); + + // Output a notice when the server closes + self.httpServer.on('close', function () { + clearInterval(connectionInterval); + logging.warn('Server has fully closed'); + }); + + // Output job queue length every 5 seconds + setInterval(() => logging.warn(`${jobService.queue.length()} jobs in the queue. Idle: ${jobService.queue.idle()}`), 5000); + } + return GhostServer.announceServerReadiness() .finally(() => { resolve(self); @@ -119,13 +139,6 @@ class GhostServer { process .removeAllListeners('SIGINT').on('SIGINT', self.shutdown.bind(self)) .removeAllListeners('SIGTERM').on('SIGTERM', self.shutdown.bind(self)); - - if (config.get('server:testmode')) { - // Debug code - setInterval(() => self.httpServer.getConnections( - (err, connections) => logging.warn(`${connections} connections currently open`) - ), 5000); - } }); }