-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgraded ponos, upgraded to loadEnv, removed clusterman.
- Loading branch information
Myztiq
committed
Dec 15, 2016
1 parent
8669640
commit d1199b3
Showing
41 changed files
with
413 additions
and
573 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.