Renamed announceServerReadiness to notifyServerStarted

- Notify is a more familiar name e.g. systemd has the sd_notify system which this is similar to
- We're actually announcing the server started, it's not actually ready for traffic (will serve 503s)
This commit is contained in:
Hannah Wolfe 2021-02-16 13:43:26 +00:00
parent b5f1c3ef6e
commit b65cb7bd7b
4 changed files with 24 additions and 23 deletions

View File

@ -255,8 +255,9 @@ async function bootGhost() {
// We are technically done here
bootLogger.log('booted');
debug('boot announcing readiness');
GhostServer.announceServerReadiness();
// @TODO: make this notification different
// debug('boot notifying readiness');
// GhostServer.notifyServerStarted();
// Init our background jobs, we don't wait for this to finish
initRecurringJobs({config});
@ -277,7 +278,7 @@ async function bootGhost() {
}
logging.error(serverStartError);
GhostServer.announceServerReadiness(serverStartError);
GhostServer.notifyServerStarted(serverStartError);
// If ghost was started and something else went wrong, we shut it down
if (ghostServer) {

View File

@ -108,8 +108,8 @@ class GhostServer {
self._startTestMode();
}
debug('server announcing readiness');
return GhostServer.announceServerReadiness()
debug('server notifying started');
return GhostServer.notifyServerStarted()
.finally(() => {
resolve(self);
});
@ -290,13 +290,13 @@ class GhostServer {
module.exports = GhostServer;
/**
* We call announce server readiness when the server is ready
* We call notify server started when the server is ready to serve traffic
* When the server is started, but not ready, it is only able to serve 503s
*
* If the server isn't able to reach readiness, announceServerReadiness is called with an error
* If the server isn't able to reach started, notifyServerStarted is called with an error
* A status message, any error, and debug info are all passed to managing processes via IPC and the bootstrap socket
*/
let announceServerReadinessCalled = false;
let notifyServerStartedCalled = false;
const debugInfo = {
versions: process.versions,
@ -305,14 +305,14 @@ const debugInfo = {
release: process.release
};
module.exports.announceServerReadiness = function (error = null) {
// If we already announced readiness, we should not do it again
if (announceServerReadinessCalled) {
module.exports.notifyServerStarted = function (error = null) {
// If we already sent a ready notification, we should not do it again
if (notifyServerStartedCalled) {
return Promise.resolve();
}
// Mark this function as called
announceServerReadinessCalled = true;
notifyServerStartedCalled = true;
// Build our message
// - if there's no error then the server is ready

View File

@ -7,7 +7,7 @@ const {events} = require('../../../core/server/lib/common');
const bootstrapSocket = require('@tryghost/bootstrap-socket');
describe('GhostServer', function () {
describe('announceServerReadiness', function () {
describe('notifyServerStarted', function () {
let GhostServer;
let socketStub;
let eventSpy;
@ -35,11 +35,11 @@ describe('GhostServer', function () {
});
it('it resolves a promise', function () {
GhostServer.announceServerReadiness().should.be.fulfilled();
GhostServer.notifyServerStarted().should.be.fulfilled();
});
it('it communicates with IPC correctly on success', function () {
GhostServer.announceServerReadiness();
GhostServer.notifyServerStarted();
process.send.calledOnce.should.be.true();
@ -50,7 +50,7 @@ describe('GhostServer', function () {
});
it('communicates with IPC correctly on failure', function () {
GhostServer.announceServerReadiness(new Error('something went wrong'));
GhostServer.notifyServerStarted(new Error('something went wrong'));
process.send.calledOnce.should.be.true();
@ -64,7 +64,7 @@ describe('GhostServer', function () {
it('communicates via bootstrap socket correctly on success', function () {
configUtils.set('bootstrap-socket', 'testing');
GhostServer.announceServerReadiness();
GhostServer.notifyServerStarted();
socketStub.calledOnce.should.be.true();
socketStub.firstCall.args[0].should.eql('testing');
@ -79,7 +79,7 @@ describe('GhostServer', function () {
it('communicates via bootstrap socket correctly on failure', function () {
configUtils.set('bootstrap-socket', 'testing');
GhostServer.announceServerReadiness(new Error('something went wrong'));
GhostServer.notifyServerStarted(new Error('something went wrong'));
socketStub.calledOnce.should.be.true();
socketStub.firstCall.args[0].should.eql('testing');
@ -95,9 +95,9 @@ describe('GhostServer', function () {
it('can be called multiple times, but only communicates once', function () {
configUtils.set('bootstrap-socket', 'testing');
GhostServer.announceServerReadiness();
GhostServer.announceServerReadiness(new Error('something went wrong'));
GhostServer.announceServerReadiness();
GhostServer.notifyServerStarted();
GhostServer.notifyServerStarted(new Error('something went wrong'));
GhostServer.notifyServerStarted();
process.send.calledOnce.should.be.true();
socketStub.calledOnce.should.be.true();

View File

@ -251,8 +251,8 @@ const freshModeGhostStart = async (options) => {
// Actually boot Ghost
await bootGhost(options);
// Ensure readiness was called (this is idempotent)
GhostServer.announceServerReadiness();
// Ensure notify was called (this is idempotent)
GhostServer.notifyServerStarted();
// Wait for the URL service to be ready, which happens after boot, but don't re-trigger db.ready
await urlServiceUtils.isFinished({disableDbReadyEvent: true});