-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminerScanner.js
69 lines (63 loc) · 1.71 KB
/
minerScanner.js
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
#!/usr/bin/env node
const request = require('request');
const async = require('async')
const SamarthyaMiner = '65535C0aEf82429F9b8e714f279d3490F2E929B7'
function getData(address) {
return new Promise((resolve, reject) => {
request(`https://api.ethermine.org/miner/:${address}/workers`, function (error, response, body) {
//console.log('error:', error);
//console.log('statusCode:', response && response.statusCode);
//console.log('body:', body);
if (response.statusCode !== 200) {
reject(body);
} else {
resolve(body);
}
});
}).catch((error) => {
console.log(error);
});
}
function checkMiners(data) {
data = JSON.parse(data);
let minersToRestart = []
return new Promise((resolve,reject) => {
async.each(data.data, function(dataEl, cb) {
//console.log(dataEl.reportedHashrate);
if (dataEl.reportedHashrate === 0) {
minersToRestart.push(dataEl.worker)
}
cb();
});
resolve(minersToRestart);
});
}
function restartMiner(miner) {
if (miner === 'miner01') {
var spawn = require('child_process').spawn,
restartMiner = spawn('python', 'restartMiner.py');
console.log('restarted miner1');
}
if (miner === 'miner02') {
//add restart code here
}
if (miner === 'miner03') {
//add restart code here
}
}
function test() {
var dataPromise = getData(SamarthyaMiner);
dataPromise.then((result) => {
minerPromise = checkMiners(result);
minerPromise.then((arr) => {
//console.log(arr);
if (arr.length !== 0) {
console.log("Miner Down!");
for (let i = 0; i < arr.length; i++) {
restartMiner(arr[i]);
}
}
});
});
}
setInterval(test, 900000);