Adds graceful shutdown handler for mongodb (#3706)
This commit is contained in:
committed by
Arthur Cinader
parent
906fb27389
commit
e7a45cecb7
@@ -97,6 +97,17 @@ export class MongoStorageAdapter {
|
|||||||
|
|
||||||
// MaxTimeMS is not a global MongoDB client option, it is applied per operation.
|
// MaxTimeMS is not a global MongoDB client option, it is applied per operation.
|
||||||
this._maxTimeMS = mongoOptions.maxTimeMS;
|
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() {
|
connect() {
|
||||||
|
|||||||
Reference in New Issue
Block a user