mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-17 05:21:27 +02:00
Adding ZMQ and SocketIO access.
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
const debug = require("debug")("worker");
|
||||
const async = require("async");
|
||||
const sprintf = require("sprintf-js").sprintf;
|
||||
const zmq = require('zmq');
|
||||
const sock = zmq.socket('pub');
|
||||
|
||||
let threadName = "Worker Server ";
|
||||
let cycleCount = 0;
|
||||
sock.bindSync('tcp://127.0.0.1:3000');
|
||||
|
||||
function updateShareStats() {
|
||||
// This is an omni-worker to deal with all things share-stats related
|
||||
@@ -12,6 +15,7 @@ function updateShareStats() {
|
||||
// Buffer lengths? You guessed it, configured in SQL.
|
||||
// Stats timeouts are 30 seconds, so everything for buffers should be there.
|
||||
let currentTime = Date.now();
|
||||
let activeAddresses = [];
|
||||
async.waterfall([
|
||||
function (callback) {
|
||||
global.coinFuncs.getLastBlockHeader(function (body) {
|
||||
@@ -173,6 +177,9 @@ function updateShareStats() {
|
||||
if (globalMinerList.indexOf(miner) === -1) {
|
||||
globalMinerList.push(miner);
|
||||
}
|
||||
if (miner.indexOf('-') === -1){
|
||||
activeAddresses.push(miner);
|
||||
}
|
||||
let cachedData = global.database.getCache(miner);
|
||||
if (cachedData !== false) {
|
||||
cachedData.hash = Math.floor(localStats.miners[miner] / 600);
|
||||
@@ -241,7 +248,9 @@ function updateShareStats() {
|
||||
cycleCount += 1;
|
||||
if (cycleCount === 6){
|
||||
cycleCount = 0;
|
||||
sock.send(['miner_hash_graph', JSON.stringify(activeAddresses)]);
|
||||
}
|
||||
sock.send(['miner_hash_stats', JSON.stringify(activeAddresses)]);
|
||||
});
|
||||
setTimeout(updateShareStats, 10000);
|
||||
}
|
||||
@@ -333,6 +342,7 @@ function updatePoolStats(poolType) {
|
||||
totalPayments: result[7] || 0,
|
||||
roundHashes: result[8] || 0
|
||||
});
|
||||
sock.send(['pool_stats', poolType]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -430,6 +440,7 @@ function updateBlockHeader() {
|
||||
value: body.result.block_header.reward,
|
||||
ts: body.result.block_header.timestamp
|
||||
});
|
||||
sock.send(['network_block_info', 'complete']);
|
||||
} else {
|
||||
console.error("GetLastBlockHeader Error during block header update");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user