Handle shutdown on grid adapters (#5943)

* Handle shutdown on grid adapters

* Add tests

* Fix postgres test
This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-08-19 00:35:06 -07:00
committed by Diamond Lewis
parent f5ac94ddb2
commit c951e08f63
6 changed files with 81 additions and 21 deletions

View File

@@ -114,18 +114,22 @@ class ParseServer {
}
handleShutdown() {
const { adapter } = this.config.databaseController;
if (adapter && typeof adapter.handleShutdown === 'function') {
const promise = adapter.handleShutdown();
if (promise instanceof Promise) {
return promise.then(() => {
if (this.config.serverCloseComplete) {
this.config.serverCloseComplete();
}
});
}
const promises = [];
const { adapter: databaseAdapter } = this.config.databaseController;
if (
databaseAdapter &&
typeof databaseAdapter.handleShutdown === 'function'
) {
promises.push(databaseAdapter.handleShutdown());
}
return Promise.resolve().then(() => {
const { adapter: fileAdapter } = this.config.filesController;
if (fileAdapter && typeof fileAdapter.handleShutdown === 'function') {
promises.push(fileAdapter.handleShutdown());
}
return (promises.length > 0
? Promise.all(promises)
: Promise.resolve()
).then(() => {
if (this.config.serverCloseComplete) {
this.config.serverCloseComplete();
}