Wait for connections to MongoDB and redis to be established on startup. Added configuration option to specify redis DB.

This commit is contained in:
Zaid Abdulla committed 2014-07-19 06:54:09 +03:00
1 parent 28394af707
commit 1c902af363
5 files changed
+84 -47

No files matched your search

+18 -14
View File
@@ -559,20 +559,24 @@ cluster = require 'cluster'
numCPUs = require('os').cpus().length
if cluster.isMaster
db.redisClient.flushdb()
cluster.on('listening', (worker, address) ->
util.log("Worker #{worker.process.pid} listening to #{address.address}:#{address.port}")
)
db.connect((err) ->
throw err if err
db.redisClient.flushdb()
db.disconnect()
cluster.on('listening', (worker, address) ->
util.log("Worker #{worker.process.pid} listening to #{address.address}:#{address.port}")
)
cluster.on('exit', (worker, code, signal) ->
util.log("Worker #{worker.process.pid} died (#{worker.process.exitCode})")
setTimeout(()->
cluster.on('exit', (worker, code, signal) ->
util.log("Worker #{worker.process.pid} died (#{worker.process.exitCode})")
setTimeout(()->
cluster.fork()
, config.WORKER_RESPAWN_TIME)
)
for [1 .. numCPUs]
cluster.fork()
, config.WORKER_RESPAWN_TIME)
)
for [1 .. numCPUs]
cluster.fork()
else
options = {
key: fs.readFileSync('../config/httpscert.key'),
@@ -582,8 +586,8 @@ else
httpServer = http.createServer(listener)
httpsServer = https.createServer(options, listener)
# wait until DB connections are established
setTimeout(() ->
db.connect((err) ->
throw err if err
httpServer.listen(config.ACS_PORT, config.ACS_INTERFACE)
httpsServer.listen(config.ACS_HTTPS_PORT, config.ACS_HTTPS_INTERFACE)
, 1000)
)