meshblu-server-websocket
Version:
Websocket Protocol Adapter for Meshblu
49 lines (41 loc) • 1.48 kB
text/coffeescript
_ = require 'lodash'
redis = require 'redis'
RedisNS = require '@octoblu/redis-ns'
Server = require './src/server'
{Pool} = require 'generic-pool'
MeshbluConfig = require 'meshblu-config'
class Command
constructor: ->
port = process.env.PORT ? 80
namespace = process.env.NAMESPACE ? 'meshblu'
redisUri = process.env.REDIS_URI
redisMaxConnections = process.env.REDIS_MAX_CONNECTIONS ? 100
redisMaxConnections = parseInt redisMaxConnections
meshbluConfig = new MeshbluConfig().toJSON()
timeoutSeconds = process.env.JOB_TIMEOUT_SECONDS ? 30
timeoutSeconds = parseInt timeoutSeconds
pool = {namespace, redisUri, redisMaxConnections}
= new Server {port, meshbluConfig, pool, timeoutSeconds}
run: =>
.start (error) =>
return error if error?
{address,port} = .address()
console.log "listening on #{address}:#{port}"
process.on 'SIGTERM', =>
console.log 'SIGTERM received, shutting down'
.stop =>
process.exit 0
buildPool: ({namespace, redisUri, redisMaxConnections}) =>
pool = new Pool
max: redisMaxConnections
min: 0
create: (callback) =>
client = _.bindAll new RedisNS namespace, redis.createClient(redisUri)
callback null, client
destroy: (client) =>
client.end true
panic: (error) =>
console.error error.stack
process.exit 1
command = new Command
command.run()