loopback-connector-elastic-search icon indicating copy to clipboard operation
loopback-connector-elastic-search copied to clipboard

Connector calls don't wait until its initialized

Open pulkitsinghal opened this issue 9 years ago • 1 comments

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.

pulkitsinghal avatar Apr 03 '15 01:04 pulkitsinghal

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();
  });

};

mrfelton avatar Aug 05 '15 14:08 mrfelton