Support: serverCloseComplete option (#5937)

* Support: serverCloseComplete option

Callback when server has fully shutdown.

Please check that all cases are covered.

* handle error on startup

* fix tests

* test workaround

* remove serverCloseComplete chech on startup failure
This commit is contained in:
Diamond Lewis
2019-08-19 00:25:52 -05:00
committed by GitHub
parent 994cdb7cb5
commit 1064f0c3fb
5 changed files with 28 additions and 4 deletions

View File

@@ -62,6 +62,7 @@ describe('Server Url Checks', () => {
collectionPrefix: 'test_',
});
}
let close = false;
const newConfiguration = Object.assign({}, defaultConfiguration, {
databaseAdapter,
serverStartComplete: () => {
@@ -71,10 +72,14 @@ describe('Server Url Checks', () => {
done.fail('Close Server Error');
}
reconfigureServer({}).then(() => {
expect(close).toBe(true);
done();
});
});
},
serverCloseComplete: () => {
close = true;
},
});
const parseServer = ParseServer.start(newConfiguration);
});

View File

@@ -330,6 +330,14 @@ module.exports.ParseServerOptions = {
action: parsers.numberParser('schemaCacheTTL'),
default: 5000,
},
serverCloseComplete: {
env: 'PARSE_SERVER_SERVER_CLOSE_COMPLETE',
help: 'Callback when server has closed',
},
serverStartComplete: {
env: 'PARSE_SERVER_SERVER_START_COMPLETE',
help: 'Callback when server has started',
},
serverURL: {
env: 'PARSE_SERVER_URL',
help: 'URL to your parse server with http:// or https://.',

View File

@@ -59,6 +59,8 @@
* @property {Boolean} revokeSessionOnPasswordReset When a user changes their password, either through the reset password email or while logged in, all sessions are revoked if this is true. Set to false if you don't want to revoke sessions.
* @property {Boolean} scheduledPush Configuration for push scheduling, defaults to false.
* @property {Number} schemaCacheTTL The TTL for caching the schema for optimizing read/write operations. You should put a long TTL when your DB is in production. default to 5000; set 0 to disable.
* @property {Function} serverCloseComplete Callback when server has closed
* @property {Function} serverStartComplete Callback when server has started
* @property {String} serverURL URL to your parse server with http:// or https://.
* @property {Number} sessionLength Session duration, in seconds, defaults to 1 year
* @property {Boolean} silent Disables console output

View File

@@ -199,8 +199,10 @@ export interface ParseServerOptions {
:ENV: PARSE_SERVER_PLAYGROUND_PATH
:DEFAULT: /playground */
playgroundPath: ?string;
/* Callback when server has started */
serverStartComplete: ?(error: ?Error) => void;
/* Callback when server has closed */
serverCloseComplete: ?() => void;
}
export interface CustomPagesOptions {

View File

@@ -89,7 +89,6 @@ class ParseServer {
if (serverStartComplete) {
serverStartComplete(error);
} else {
// eslint-disable-next-line no-console
console.error(error);
process.exit(1);
}
@@ -119,10 +118,18 @@ class ParseServer {
if (adapter && typeof adapter.handleShutdown === 'function') {
const promise = adapter.handleShutdown();
if (promise instanceof Promise) {
return promise;
return promise.then(() => {
if (this.config.serverCloseComplete) {
this.config.serverCloseComplete();
}
});
}
}
return Promise.resolve();
return Promise.resolve().then(() => {
if (this.config.serverCloseComplete) {
this.config.serverCloseComplete();
}
});
}
/**