Handle shutdown on grid adapters (#5943)
* Handle shutdown on grid adapters * Add tests * Fix postgres test
This commit is contained in:
committed by
Diamond Lewis
parent
f5ac94ddb2
commit
c951e08f63
@@ -32,7 +32,10 @@ export class GridFSBucketAdapter extends FilesAdapter {
|
||||
this._connectionPromise = MongoClient.connect(
|
||||
this._databaseURI,
|
||||
this._mongoOptions
|
||||
).then(client => client.db(client.s.options.dbName));
|
||||
).then(client => {
|
||||
this._client = client;
|
||||
return client.db(client.s.options.dbName);
|
||||
});
|
||||
}
|
||||
return this._connectionPromise;
|
||||
}
|
||||
@@ -98,6 +101,13 @@ export class GridFSBucketAdapter extends FilesAdapter {
|
||||
const bucket = await this._getBucket();
|
||||
return bucket.openDownloadStreamByName(filename);
|
||||
}
|
||||
|
||||
handleShutdown() {
|
||||
if (!this._client) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this._client.close(false);
|
||||
}
|
||||
}
|
||||
|
||||
export default GridFSBucketAdapter;
|
||||
|
||||
@@ -33,7 +33,10 @@ export class GridStoreAdapter extends FilesAdapter {
|
||||
this._connectionPromise = MongoClient.connect(
|
||||
this._databaseURI,
|
||||
this._mongoOptions
|
||||
).then(client => client.db(client.s.options.dbName));
|
||||
).then(client => {
|
||||
this._client = client;
|
||||
return client.db(client.s.options.dbName);
|
||||
});
|
||||
}
|
||||
return this._connectionPromise;
|
||||
}
|
||||
@@ -99,6 +102,13 @@ export class GridStoreAdapter extends FilesAdapter {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
handleShutdown() {
|
||||
if (!this._client) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return this._client.close(false);
|
||||
}
|
||||
}
|
||||
|
||||
export default GridStoreAdapter;
|
||||
|
||||
Reference in New Issue
Block a user