loopback-connector-elastic-search
loopback-connector-elastic-search copied to clipboard
Connector calls don't wait until its initialized
Any pointers to code would be appreciated.
I thought I had already accomplished the right flow via these lines of code:
dataSource.connector.connect(callback);
...
ESConnector.prototype.connect = function (callback) {
...
if(self.settings.mappings) {
self.setupMappings(callback);
}
...
But apparently not.
connectors emit a connected
event once the connecter has finished initialising. Are connectors supposed to queue up their queries somehow until the connected event has been emitted?
As a workaround in our application, we have a boot script like this which ensures that queries are not made against the connector until it is truly ready:
'use strict';
var logger = require('../modules/fc/logger');
module.exports = function (app, cb) {
logger.debug('Boot waiting for ElasticSearch initialization...');
// As soon as the datasource has been connected, move on.
app.dataSources.elasticsearch.once('connected', function () {
logger.debug('ElasticSearch connected, boot continuing');
cb();
});
};