History keeper is now separated from chainpad-server

This commit is contained in:
yflory
2019-03-29 17:03:53 +01:00
parent babb91686d
commit f24d34c0af
3 changed files with 637 additions and 5 deletions

View File

@@ -245,7 +245,9 @@ if (config.httpSafePort) {
var wsConfig = { server: httpServer };
var rpc;
var historyKeeper;
// Initialize tasks, then rpc, then store, then history keeper and then start the server
var nt = nThen(function (w) {
if (!config.enableTaskScheduling) { return; }
var Tasks = require("./storage/tasks");
@@ -253,6 +255,11 @@ var nt = nThen(function (w) {
Tasks.create(config, w(function (e, tasks) {
config.tasks = tasks;
}));
}).nThen(function (w) {
if (config.useExternalWebsocket) { return; }
Storage.create(config, w(function (_store) {
config.store = _store;
}));
}).nThen(function (w) {
config.rpc = typeof(config.rpc) === 'undefined'? './rpc.js' : config.rpc;
if (typeof(config.rpc) !== 'string') { return; }
@@ -266,15 +273,22 @@ var nt = nThen(function (w) {
rpc = _rpc;
}));
}).nThen(function () {
if(config.useExternalWebsocket) { return; }
if (config.useExternalWebsocket) { return; }
var HK = require('./historyKeeper.js');
var hkConfig = {
tasks: config.tasks,
rpc: rpc,
store: config.store
};
historyKeeper = HK.create(hkConfig);
}).nThen(function () {
if (config.useExternalWebsocket) { return; }
if (websocketPort !== config.httpPort) {
console.log("setting up a new websocket server");
wsConfig = { port: websocketPort};
}
var wsSrv = new WebSocketServer(wsConfig);
Storage.create(config, function (store) {
NetfluxSrv.run(store, wsSrv, config, rpc);
});
NetfluxSrv.run(wsSrv, config, historyKeeper);
});
if (config.debugReplName) {