Skip to content

Commit e7fbfeb

Browse files
committed
Only start the server when all data sources are ready.
1 parent 77659ac commit e7fbfeb

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

bin/ldf-server

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,20 @@ else {
159159
};
160160
}
161161

162-
// Create and start server
163-
var server = new LinkedDataFragmentsServer(config);
164-
server.listen(port);
165-
console.log('Worker %d running on http://localhost:%d/.', process.pid, port);
162+
// Create server, and start it when all data sources are ready
163+
var server = new LinkedDataFragmentsServer(config),
164+
pending = _.size(datasources);
165+
_.each(datasources, function (settings) {
166+
var ready = _.once(startWhenReady);
167+
settings.datasource.once('initialized', ready);
168+
settings.datasource.once('error', ready);
169+
});
170+
function startWhenReady() {
171+
if (!--pending) {
172+
server.listen(port);
173+
console.log('Worker %d running on http://localhost:%d/.', process.pid, port);
174+
}
175+
}
166176

167177
// Terminate gracefully if possible
168178
process.once('SIGINT', function () {

0 commit comments

Comments
 (0)