Skip to content

Commit

Permalink
Upgraded ponos, upgraded to loadEnv, removed clusterman.
Browse files Browse the repository at this point in the history
  • Loading branch information
Myztiq committed Dec 15, 2016
1 parent 8669640 commit d1199b3
Show file tree
Hide file tree
Showing 41 changed files with 413 additions and 573 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
98 changes: 42 additions & 56 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,55 @@
/**
* @module index
*/
'use strict';
require('loadenv.js');

require('loadenv')();

// leave this newrelic require up here!
if (process.env.NEW_RELIC_LICENSE_KEY) {
require('newrelic');
}

var ClusterManager = require('cluster-man');
var numCPUs = require('os').cpus().length;
var rollbar = require('rollbar');
const log = require('logger').child({module: 'Navi'});
const Server = require('server.js');
const workerServer = require('worker.js');

var App = require('app');
var WorkerServer = require('models/worker-server');
var log = require('middlewares/logger')(__filename).log;
const httpServer = new Server()
const Navi = {};
Navi.start = () => {
return Promise.all([
workerServer.start(),
httpServer.start()
])
.then(() => {
log.trace('Started Navi');
process.on('SIGINT', Navi.stop);
process.on('SIGTERM', Navi.stop);
})
.catch((e) => {
log.fatal({error: e}, 'Error starting server');
throw e;
});
};

var manager = new ClusterManager({
worker: function () {
var app = new App();
WorkerServer.listen(function (err) {
if (err) {
log.error({
err: err
}, 'WorkerServer.listen error');
throw err;
}
app.start(function (err) {
if (err) {
log.error({
err: err
}, 'app.start error');
throw err;
} else {
log.info('app.start success');
}
});
Navi.stop = () => {
process.removeListener('SIGINT', Navi.stop);
process.removeListener('SIGTERM', Navi.stop);
return Promise.all([
workerServer.stop(),
httpServer.stop()
])
.then(() => {
log.trace('Stopped Navi');
})
.catch((e) => {
log.fatal({error: e}, 'Error stopping server');
throw e;
});
},
master: function () {
log.info('app.start master');
},
numWorkers: (process.env.ENABLE_CLUSTERING) ? (process.env.NUM_CLUSTER_WORKERS || numCPUs) : 1,
killOnError: false,
beforeExit: function (err, done) {
if (err) {
rollbar.handleErrorWithPayloadData(err, {level: 'fatal'}, null, function () {
log.error({ err: err }, 'manager.beforeExit error');
closeWorkerServer();
})
} else {
log.info('manager.beforeExit');
closeWorkerServer();
}
};

function closeWorkerServer () {
WorkerServer.stop(function (err) {
if (err) {
log.error({ err: err }, 'manager.beforeExit WorkerServer stop error');
}
done();
});
}
}
process.on('uncaughtException', function (err) {
log.fatal({
err: err
}, 'stopping app due too uncaughtException')
Navi.stop()
});

manager.start();
Navi.start();
41 changes: 0 additions & 41 deletions lib/app.js

This file was deleted.

25 changes: 0 additions & 25 deletions lib/hermes.js

This file was deleted.

54 changes: 0 additions & 54 deletions lib/loadenv.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module lib/logger
*/
'use strict';
require('./loadenv.js');
require('loadenv')();

var bunyan = require('bunyan');
var keypather = require('keypather')();
Expand Down
2 changes: 1 addition & 1 deletion lib/models/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @module lib/models/api
*/
'use strict';
require('loadenv.js');
require('loadenv')();

var ErrorCat = require('error-cat');
var keypather = require('keypather')();
Expand Down
2 changes: 1 addition & 1 deletion lib/models/error-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module lib/models/error-page
*/
'use strict';
require('loadenv.js');
require('loadenv')();

var ErrorCat = require('error-cat');
var qs = require('querystring');
Expand Down
2 changes: 1 addition & 1 deletion lib/models/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module lib/models/proxy
*/
'use strict';
require('../loadenv.js');
require('loadenv')();

var assign = require('101/assign');
var defaults = require('101/defaults');
Expand Down
2 changes: 1 addition & 1 deletion lib/models/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module lib/models/redis
*/
'use strict';
require('../loadenv.js');
require('loadenv')();

var fs = require('fs');
var redis = require('redis');
Expand Down
6 changes: 3 additions & 3 deletions lib/models/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module lib/models/server
*/
'use strict';
require('../loadenv.js');
require('loadenv')();

var async = require('async');
var domain = require('domain');
Expand Down Expand Up @@ -104,8 +104,8 @@ Server.prototype._setupDomainTid = function (req, res, next) {
Server.prototype._setupMiddleware = function () {
log.info('Server.prototype._setupMiddlware');
this.app.get('/robots.txt', this.serveRobots);
this.app.use('/health-610f09d0-8502-11e6-8cce-e3c360b6e938', (req, res) => {
res.status(200).send()
this.app.use('/health-610f09d0-8502-11e6-8cce-e3c360b6e938', (req, res) => {
res.status(200).send()
})
// NOTE: mw only works for non web socket request
// to include middleware for ws add to _handleUserWsRequest
Expand Down
65 changes: 0 additions & 65 deletions lib/models/worker-server.js

This file was deleted.

Loading

0 comments on commit d1199b3

Please sign in to comment.