-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker.coffee
41 lines (29 loc) · 966 Bytes
/
worker.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Start clustered docas workers and restart on exit.
cluster = require 'cluster'
numCPUs = require('os').cpus().length
if cluster.isMaster
for i in [0...numCPUs]
cluster.fork()
console.log 'worker started'
cluster.on 'exit', (worker, code, signal) ->
exitCode = worker.process.exitCode;
console.log 'worker ' + worker.pid + ' died (' + exitCode + '). restarting...'
cluster.fork()
else
# ## Worker Configuration
fairy = require('fairy').connect()
{spawn} = require 'child_process'
fairy.queue('DOCAS').regist (repo, callback) ->
child_process = spawn "docas", [repo]
output = ''
child_process.stdout.on 'data', (data) ->
process.stdout.write data
output += data
child_process.stderr.on 'data', (data) ->
process.stderr.write data
output += data
child_process.on 'exit', (code) ->
return callback() unless code
callback
do: 'retry'
message: output