update deps and add a bunch of debug logging

This commit is contained in:
AJ ONeal 2017-05-10 23:26:25 +00:00
parent 25e644bb5d
commit e855e159f9
4 changed files with 33 additions and 8 deletions

View File

@ -71,6 +71,7 @@ cluster.on('online', function (worker) {
// calls init if init has not been called // calls init if init has not been called
require('../lib/master').touch(info.conf, state).then(function (newConf) { require('../lib/master').touch(info.conf, state).then(function (newConf) {
worker.send({ type: 'walnut.webserver.onrequest', conf: newConf }); worker.send({ type: 'walnut.webserver.onrequest', conf: newConf });
newConf.addWorker(worker);
}); });
} }

View File

@ -46,13 +46,20 @@ function init(conf, state) {
var cstore = require('cluster-store'); var cstore = require('cluster-store');
var sqlite3 = require('sqlite3-cluster/server'); 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([ var promise = PromiseA.all([
cstore.create({ cstorePromise.then(function (store) {
sock: conf.memstoreSock console.log('[walnut] [master] cstore created');
, serve: cluster.isMaster && conf.memstoreSock //console.log(cstoreOpts);
, store: cluster.isMaster && null //new require('express-session/session/memory')() //console.log(store);
// TODO implement return store;
, key: conf.ipcKey
}) })
, sqlite3.createServer({ , sqlite3.createServer({
verbose: null verbose: null
@ -65,6 +72,9 @@ function init(conf, state) {
]).then(function (args) { ]).then(function (args) {
state.memstore = args[0]; state.memstore = args[0];
//state.sqlstore = args[1]; //state.sqlstore = args[1];
newConf.addWorker = function (w) {
return cstorePromise.addWorker(w);
};
return newConf; return newConf;
}); });

View File

@ -1,6 +1,8 @@
'use strict'; 'use strict';
module.exports.create = function (webserver, xconfx, state) { module.exports.create = function (webserver, xconfx, state) {
console.log('[worker] create');
xconfx.debug = true;
console.log('DEBUG create worker'); console.log('DEBUG create worker');
if (!state) { if (!state) {
@ -35,6 +37,7 @@ module.exports.create = function (webserver, xconfx, state) {
*/ */
var cstore = require('cluster-store'); var cstore = require('cluster-store');
console.log('[worker] creating data stores...');
return PromiseA.all([ return PromiseA.all([
// TODO security on memstore // TODO security on memstore
// TODO memstoreFactory.create // TODO memstoreFactory.create
@ -44,6 +47,7 @@ module.exports.create = function (webserver, xconfx, state) {
// TODO implement // TODO implement
, key: xconfx.ipcKey , key: xconfx.ipcKey
}).then(function (_memstore) { }).then(function (_memstore) {
console.log('[worker] cstore created');
memstore = PromiseA.promisifyAll(_memstore); memstore = PromiseA.promisifyAll(_memstore);
return memstore; return memstore;
}) })
@ -52,8 +56,12 @@ module.exports.create = function (webserver, xconfx, state) {
, systemFactory.create({ , systemFactory.create({
init: true init: true
, dbname: 'config' , dbname: 'config'
}).then(function (sysdb) {
console.log('[worker] sysdb created');
return sysdb;
}) })
]).then(function (args) { ]).then(function (args) {
console.log('[worker] database factories created');
memstore = args[0]; memstore = args[0];
sqlstores.config = args[1]; sqlstores.config = args[1];
@ -70,7 +78,6 @@ module.exports.create = function (webserver, xconfx, state) {
, indices: [ 'createdAt', 'updatedAt' ] , indices: [ 'createdAt', 'updatedAt' ]
} }
]; ];
console.log('config directive', dir);
function scopeMemstore(expId) { function scopeMemstore(expId) {
var scope = expId + '|'; var scope = expId + '|';
@ -120,8 +127,11 @@ module.exports.create = function (webserver, xconfx, state) {
} }
return wrap.wrap(sqlstores.config, dir).then(function (models) { return wrap.wrap(sqlstores.config, dir).then(function (models) {
console.log('[worker] database wrapped');
return models.ComDaplieWalnutConfig.find(null, { limit: 100 }).then(function (results) { 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) { return models.ComDaplieWalnutConfig.find(null, { limit: 10000 }).then(function (redirects) {
console.log('[worker] configuring express');
var express = require('express-lazy'); var express = require('express-lazy');
var app = express(); var app = express();
var recase = require('connect-recase')({ var recase = require('connect-recase')({
@ -160,15 +170,19 @@ module.exports.create = function (webserver, xconfx, state) {
} }
function setupMain() { function setupMain() {
if (xconfx.debug) { console.log('[main] setup'); }
mainApp = express(); mainApp = express();
require('./main').create(mainApp, xconfx, apiFactories, apiDeps).then(function () { require('./main').create(mainApp, xconfx, apiFactories, apiDeps).then(function () {
if (xconfx.debug) { console.log('[main] ready'); }
// TODO process.send({}); // TODO process.send({});
}); });
} }
if (!bootstrapApp) { if (!bootstrapApp) {
if (xconfx.debug) { console.log('[bootstrap] setup'); }
bootstrapApp = express(); bootstrapApp = express();
require('./bootstrap').create(bootstrapApp, xconfx, models).then(function () { require('./bootstrap').create(bootstrapApp, xconfx, models).then(function () {
if (xconfx.debug) { console.log('[bootstrap] ready'); }
// TODO process.send({}); // TODO process.send({});
setupMain(); setupMain();
}); });

View File

@ -45,7 +45,7 @@
"body-parser": "1.x", "body-parser": "1.x",
"btoa": "1.x", "btoa": "1.x",
"bytes": "^1.0.0", "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", "compression": "1.x",
"connect": "3.x", "connect": "3.x",
"connect-cors": "0.5.x", "connect-cors": "0.5.x",