Skip to content
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

Removes un-necessary shutdown handler #3786

Merged
merged 2 commits into from
May 8, 2017
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
18 changes: 7 additions & 11 deletions src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,6 @@ export class MongoStorageAdapter {

// MaxTimeMS is not a global MongoDB client option, it is applied per operation.
this._maxTimeMS = mongoOptions.maxTimeMS;
process.on('SIGTERM', this.handleShutdown(this));
process.on('SIGINT', this.handleShutdown(this));
}

handleShutdown(storageAdapter) {
return () => {
if (!storageAdapter.database) {
return;
}
storageAdapter.database.close(false);
}
}

connect() {
Expand Down Expand Up @@ -139,6 +128,13 @@ export class MongoStorageAdapter {
return this.connectionPromise;
}

handleShutdown() {
if (!this.database) {
return;
}
this.database.close(false);
}

_adaptiveCollection(name: string) {
return this.connect()
.then(() => this.database.collection(this._collectionPrefix + name))
Expand Down
7 changes: 7 additions & 0 deletions src/ParseServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ class ParseServer {
return ParseServer.app(this.config);
}

handleShutdown() {
const { adapter } = this.config.databaseController;
if (adapter && typeof adapter.handleShutdown === 'function') {
adapter.handleShutdown();
}
}

static app({maxUploadSize = '20mb', appId}) {
// This app serves the Parse API directly.
// It's the equivalent of https://api.parse.com/1 in the hosted Parse API.
Expand Down
7 changes: 4 additions & 3 deletions src/cli/parse-server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import express from 'express';
import { ParseServer } from '../index';
import ParseServer from '../index';
import definitions from './definitions/parse-server';
import cluster from 'cluster';
import os from 'os';
Expand Down Expand Up @@ -43,9 +43,9 @@ function startServer(options, callback) {
app.use(middleware);
}

const api = new ParseServer(options);
const parseServer = new ParseServer(options);
const sockets = {};
app.use(options.mountPath, api);
app.use(options.mountPath, parseServer.app);

const server = app.listen(options.port, options.host, callback);
server.on('connection', initializeConnections);
Expand Down Expand Up @@ -85,6 +85,7 @@ function startServer(options, callback) {
console.log('Termination signal received. Shutting down.');
destroyAliveConnections();
server.close();
parseServer.handleShutdown();
};
process.on('SIGTERM', handleShutdown);
process.on('SIGINT', handleShutdown);
Expand Down