cavalry
Version:
Basically Fleet without dnode.
49 lines (43 loc) • 1.35 kB
text/coffeescript
WebSocket = require 'ws'
runner = require('../lib/runner')
util = require('../lib/util')
router = require '../lib/router'
Checkin = (innerOpts={})->
=
hostname: process.env.MASTERHOST or "localhost"
port: process.env.MASTERPORT or 4000
secret: process.env.MASTERPASS or 'testingpass'
= innerOpts
= true
return this
Checkin.prototype.setRetry = (state) ->
= state
Checkin.prototype.startCheckin = ->
checkinMessage = =>
JSON.stringify
secret: .secret
type: "checkin"
id: runner.slaveId.toString()
processes: util.clone runner.processes
routingTableHash: router.currentHash
apiVersion: util.apiVersion
ws = new WebSocket "ws://#{@opts.hostname}:#{@opts.port}"
ws.on 'open', =>
ws.send checkinMessage()
= setInterval ->
ws.send checkinMessage()
, 500
ws.on 'close', =>
clearInterval
console.log "Checkin connection closed" unless .silent
setTimeout =>
() if
, 500
ws.on 'error', (err) =>
clearInterval
console.log "Checkin connection errored with", err unless .silent
setTimeout =>
() if
, 500
module.exports = (opts) ->
new Checkin opts