Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (74 loc) · 2.13 KB
/
Copy pathindex.js
File metadata and controls
89 lines (74 loc) · 2.13 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"use strict"
const cluster = require('cluster'),
stopSignals = [
'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
];
cluster.on('disconnect', function(worker) {
console.log('worker %d died. restarting...', worker.process.pid);
cluster.fork();
});
cluster.on('exit', (worker, code, signal) => {
console.log('worker %d died (%s). restarting...', worker.process.pid, signal || code);
cluster.fork();
});
if (cluster.isMaster) {
console.log('Starting worker...');
cluster.fork();
stopSignals.forEach(function (signal) {
process.on(signal, function () {
console.log(`Got ${signal}, stopping workers...`);
cluster.disconnect(function () {
console.log('All workers stopped, exiting.');
process.exit(0);
});
});
});
} else {
const { logs:logs,
bots:bots,
trades:trades
} = require('./models'),
server = require('./server'),
conns = require('./conns'),
signals = require('./signals');
logs.config(conns.wss.broadcast);
logs.log('Worker started.');
server(logs,bots,trades,conns.wss);
var poloniex = conns.configPolo(logs);
console.log('Configuring...');
signals
.config(poloniex)
.catch(err=>{logs.log('Error configuring signals: '+err);})
.then(()=>{
bots.config(
conns.wss.broadcast,
logs,
poloniex,
signals
);
trades.config(
conns.wss.broadcast,
bots,
logs,
signals
);
console.log('Configuration complete.');
poloniex.openWebSocket({version:2});
function runBots(){
bots
.run()
.then(()=>{runBots();})
.catch(err=>{logs.log('Error running bots: '+err);});
}
runBots();
function runTrades(){
trades
.run()
.then(()=>{runTrades();})
.catch(err=>{logs.log('Error running trades: '+err);});
}
runTrades();
})
.catch(err=>{logs.log('Error running bots and trades: '+err);});
}