From e855e159f91e384cebc9fa4c1d34024843cf625b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 10 May 2017 23:26:25 +0000 Subject: [PATCH] update deps and add a bunch of debug logging --- boot/master.js | 1 + lib/master.js | 22 ++++++++++++++++------ lib/worker.js | 16 +++++++++++++++- package.json | 2 +- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/boot/master.js b/boot/master.js index 9ed50ea..f96e7de 100644 --- a/boot/master.js +++ b/boot/master.js @@ -71,6 +71,7 @@ cluster.on('online', function (worker) { // calls init if init has not been called require('../lib/master').touch(info.conf, state).then(function (newConf) { worker.send({ type: 'walnut.webserver.onrequest', conf: newConf }); + newConf.addWorker(worker); }); } diff --git a/lib/master.js b/lib/master.js index ca78a57..69c757c 100644 --- a/lib/master.js +++ b/lib/master.js @@ -46,13 +46,20 @@ function init(conf, state) { var cstore = require('cluster-store'); var sqlite3 = require('sqlite3-cluster/server'); + var cstoreOpts = { + sock: conf.memstoreSock + , serve: cluster.isMaster && conf.memstoreSock + , store: cluster.isMaster && null //new require('express-session/session/memory')() + // TODO implement + , key: conf.ipcKey + }; + var cstorePromise = cstore.create(cstoreOpts); var promise = PromiseA.all([ - cstore.create({ - sock: conf.memstoreSock - , serve: cluster.isMaster && conf.memstoreSock - , store: cluster.isMaster && null //new require('express-session/session/memory')() - // TODO implement - , key: conf.ipcKey + cstorePromise.then(function (store) { + console.log('[walnut] [master] cstore created'); + //console.log(cstoreOpts); + //console.log(store); + return store; }) , sqlite3.createServer({ verbose: null @@ -65,6 +72,9 @@ function init(conf, state) { ]).then(function (args) { state.memstore = args[0]; //state.sqlstore = args[1]; + newConf.addWorker = function (w) { + return cstorePromise.addWorker(w); + }; return newConf; }); diff --git a/lib/worker.js b/lib/worker.js index dee1167..21c0fc1 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -1,6 +1,8 @@ 'use strict'; module.exports.create = function (webserver, xconfx, state) { + console.log('[worker] create'); + xconfx.debug = true; console.log('DEBUG create worker'); if (!state) { @@ -35,6 +37,7 @@ module.exports.create = function (webserver, xconfx, state) { */ var cstore = require('cluster-store'); + console.log('[worker] creating data stores...'); return PromiseA.all([ // TODO security on memstore // TODO memstoreFactory.create @@ -44,6 +47,7 @@ module.exports.create = function (webserver, xconfx, state) { // TODO implement , key: xconfx.ipcKey }).then(function (_memstore) { + console.log('[worker] cstore created'); memstore = PromiseA.promisifyAll(_memstore); return memstore; }) @@ -52,8 +56,12 @@ module.exports.create = function (webserver, xconfx, state) { , systemFactory.create({ init: true , dbname: 'config' + }).then(function (sysdb) { + console.log('[worker] sysdb created'); + return sysdb; }) ]).then(function (args) { + console.log('[worker] database factories created'); memstore = args[0]; sqlstores.config = args[1]; @@ -70,7 +78,6 @@ module.exports.create = function (webserver, xconfx, state) { , indices: [ 'createdAt', 'updatedAt' ] } ]; - console.log('config directive', dir); function scopeMemstore(expId) { var scope = expId + '|'; @@ -120,8 +127,11 @@ module.exports.create = function (webserver, xconfx, state) { } return wrap.wrap(sqlstores.config, dir).then(function (models) { + console.log('[worker] database wrapped'); return models.ComDaplieWalnutConfig.find(null, { limit: 100 }).then(function (results) { + console.log('[worker] config query complete'); return models.ComDaplieWalnutConfig.find(null, { limit: 10000 }).then(function (redirects) { + console.log('[worker] configuring express'); var express = require('express-lazy'); var app = express(); var recase = require('connect-recase')({ @@ -160,15 +170,19 @@ module.exports.create = function (webserver, xconfx, state) { } function setupMain() { + if (xconfx.debug) { console.log('[main] setup'); } mainApp = express(); require('./main').create(mainApp, xconfx, apiFactories, apiDeps).then(function () { + if (xconfx.debug) { console.log('[main] ready'); } // TODO process.send({}); }); } if (!bootstrapApp) { + if (xconfx.debug) { console.log('[bootstrap] setup'); } bootstrapApp = express(); require('./bootstrap').create(bootstrapApp, xconfx, models).then(function () { + if (xconfx.debug) { console.log('[bootstrap] ready'); } // TODO process.send({}); setupMain(); }); diff --git a/package.json b/package.json index 0437dab..269f7df 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "body-parser": "1.x", "btoa": "1.x", "bytes": "^1.0.0", - "cluster-store": "git+https://git.daplie.com/coolaj86/cluster-store.git", + "cluster-store": "git+https://git.daplie.com/Daplie/cluster-store.git#v2", "compression": "1.x", "connect": "3.x", "connect-cors": "0.5.x",