Open aquid opened 7 years ago
@aquid - we received the following answer in the chat room:
Heath Morrison @doublemarked Jan 10 16:16
@pulkitsinghal this should not be necessary
Datasource initialization occurs before boot scripts are executed.
The datasource initialize method has a callback,
which should not be called until the datasource is fully initialized.
(afaik)
I see in your connector that you are indeed calling this callback only on connect, which makes me wonder what @aquid means when he says "without our connector being initialised” in strongloop-community/loopback-connector-elastic-search#66
@aquid I use the es connector like so as a boot script: (almost on first position, since it starts with "e" ;)):
module.exports = function (app, cb) {
console.info('Boot waiting for ElasticSearch initialization...');
var connected = false;
// As soon as the datasource has been connected, move on.
app.datasources.db.once('connected', function () {
console.info('ElasticSearch connected, boot continuing');
connected = true;
cb();
});
// I need this, otherwise, if no ES is available, it will hang forever. PM2 then autorestarts.
setTimeout(function(){
if(!connected) {
cb(new Error("retrying elasticsearch connection"));
}
}, 5000);
};```
Only "problem", the es connector does NOT retry infinitely, so at some point, the application just hangs, that's why I "restart" by throwing an error and pm2 takes over.
@wolfgang-s So the above piece of code goes before each boot scripts or just one boot scripts which run before all other and checks if elastic is up and running.
Can't we do a refresh configuration for index too? Is it possible?
This is a normal loopback boot module. Runs once before the rest of the boot modules.
I'm using PM2 which restarts the node app on failure (when it takes more than 5 seconds).
Actually almost the same as here: https://github.com/strongloop-community/loopback-connector-elastic-search/issues/7
If we try to run a boot script now without our connector being initialised we get back an error saying Index doesn't exist.
here's the error message
cc @pulkitsinghal