Skip to content

Support: serverCloseComplete option #5937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions spec/ParseServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('Server Url Checks', () => {
collectionPrefix: 'test_',
});
}
let close = false;
const newConfiguration = Object.assign({}, defaultConfiguration, {
databaseAdapter,
serverStartComplete: () => {
Expand All @@ -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);
});
Expand Down
8 changes: 8 additions & 0 deletions src/Options/Definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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://.',
Expand Down
2 changes: 2 additions & 0 deletions src/Options/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class ParseServer {
if (serverStartComplete) {
serverStartComplete(error);
} else {
// eslint-disable-next-line no-console
console.error(error);
process.exit(1);
}
Expand Down Expand Up @@ -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();
}
});
}

/**
Expand Down