maxBuffer
This commit is contained in:
@@ -17,10 +17,34 @@
|
|||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
const Fund = require('../modules/fund/fund.model');
|
const Fund = require('../modules/fund/fund.model');
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
|
const EventEmitter = require('events');
|
||||||
|
|
||||||
const mock = {
|
const mock = {
|
||||||
touch: () => {mylog.info('-----------------\n');},
|
touch: () => {mylog.info('-----------------\n');},
|
||||||
done: () => {mylog.info('done');},
|
done: () => {mylog.info('done');},
|
||||||
};
|
};
|
||||||
|
const watcher = new EventEmitter();
|
||||||
|
watcher.on('startMine', () => {
|
||||||
|
const rl = exec('node ./src/jobs/mine.js', [{maxBuffer: 1024 * 1024 * 100}],(error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(`exec error: ${error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(`stdout: ${stdout}`);
|
||||||
|
console.error(`stderr: ${stderr}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
rl.on('close', function (code) {
|
||||||
|
mylog.info('child process exited with code ' + code); // 输出到控制台
|
||||||
|
mylog.info('挖矿程序执行完毕');
|
||||||
|
});
|
||||||
|
rl.on('message', function (msg) {
|
||||||
|
mylog.info('MineInfo', msg)
|
||||||
|
});
|
||||||
|
rl.on('exit', function () {
|
||||||
|
mylog.info('挖矿程序执行完毕');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
async function confirm (job = mock, done = mock) {
|
async function confirm (job = mock, done = mock) {
|
||||||
mylog.info('[Schedule Job] 矿晶确认程序开始执行......');
|
mylog.info('[Schedule Job] 矿晶确认程序开始执行......');
|
||||||
@@ -49,21 +73,8 @@ async function confirm (job = mock, done = mock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function mineJob (job = mock, done = mock) {
|
async function mineJob (job = mock, done = mock) {
|
||||||
const rl = exec('node ./src/jobs/mine.js');
|
watcher.emit('startMine');
|
||||||
rl.stderr.on('data', function (data) {
|
return typeof done === 'function' && done('矿晶确认完成');
|
||||||
mylog.error('[mine]定时任务出错\n');
|
|
||||||
mylog.error(data);
|
|
||||||
});
|
|
||||||
rl.on('close', function (code) {
|
|
||||||
mylog.info('child process exited with code ' + code); // 输出到控制台
|
|
||||||
mylog.info('挖矿程序执行完毕');
|
|
||||||
});
|
|
||||||
rl.on('message', function () {
|
|
||||||
job.touch();
|
|
||||||
});
|
|
||||||
rl.on('exit', function () {
|
|
||||||
typeof done === 'function' && done('挖矿程序执行完毕');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const jobs = [
|
const jobs = [
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ const path = require('path');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const prettyStdOut = new PrettyStream();
|
const prettyStdOut = new PrettyStream();
|
||||||
prettyStdOut.pipe(process.stdout);
|
|
||||||
|
|
||||||
if (!fs.existsSync('minelog')) {
|
if (!fs.existsSync('minelog')) {
|
||||||
fs.mkdirSync('minelog');
|
fs.mkdirSync('minelog');
|
||||||
@@ -163,17 +162,14 @@ async function mine (job = mock, done = mock) {
|
|||||||
value: -1
|
value: -1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
typeof process.send === 'function' && process.send('tick');
|
|
||||||
}
|
}
|
||||||
currentIndex += 10;
|
currentIndex += 10;
|
||||||
probe.currentIndex = currentIndex;
|
probe.currentIndex = currentIndex;
|
||||||
}
|
}
|
||||||
mylog.info('收益计算分配完成');
|
mylog.info('收益计算分配完成');
|
||||||
typeof process.send === 'function' && process.send('tick');
|
|
||||||
await system.findOneAndUpdate({
|
await system.findOneAndUpdate({
|
||||||
key: 'userIndex4job'
|
key: 'userIndex4job'
|
||||||
}, { $set: { value: 0 } }).exec();
|
}, { $set: { value: 0 } }).exec();
|
||||||
typeof process.send === 'function' && process.send('tick');
|
|
||||||
await system.findOneAndUpdate({
|
await system.findOneAndUpdate({
|
||||||
key: 'mineCount',
|
key: 'mineCount',
|
||||||
}, {
|
}, {
|
||||||
@@ -181,20 +177,18 @@ async function mine (job = mock, done = mock) {
|
|||||||
value: 1
|
value: 1
|
||||||
}
|
}
|
||||||
}, { upsert: true });
|
}, { upsert: true });
|
||||||
typeof process.send === 'function' && process.send('tick');
|
|
||||||
await system.findOneAndUpdate({
|
await system.findOneAndUpdate({
|
||||||
key: 'lastMine',
|
key: 'lastMine',
|
||||||
}, {
|
}, {
|
||||||
value: new Date().toISOString()
|
value: new Date().toISOString()
|
||||||
}, { upsert: true });
|
}, { upsert: true });
|
||||||
typeof process.send === 'function' && process.send('tick');
|
|
||||||
typeof done === 'function' && done('收益计算分配完成');
|
typeof done === 'function' && done('收益计算分配完成');
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
const probe = {
|
const probe = {
|
||||||
currentIndex: 0
|
currentIndex: 0
|
||||||
};
|
};
|
||||||
const start = async () => {
|
const start = async (job, done) => {
|
||||||
const SysConfig = require('../../configSec');
|
const SysConfig = require('../../configSec');
|
||||||
mongoose.set('useCreateIndex', true);
|
mongoose.set('useCreateIndex', true);
|
||||||
const { DB_USER_NAME, DB_PASSWD, DB_HOST, DB_PORT, DB_NAME } = SysConfig;
|
const { DB_USER_NAME, DB_PASSWD, DB_HOST, DB_PORT, DB_NAME } = SysConfig;
|
||||||
@@ -219,6 +213,9 @@ const start = async () => {
|
|||||||
process.on('SIGINT', beforeExit);
|
process.on('SIGINT', beforeExit);
|
||||||
process.on('uncaughtException', beforeExit);
|
process.on('uncaughtException', beforeExit);
|
||||||
process.on('unhandledRejection', beforeExit);
|
process.on('unhandledRejection', beforeExit);
|
||||||
mine();
|
typeof process.send === 'function' && process.send('子进程开始执行mine');
|
||||||
|
mine(job, done);
|
||||||
|
typeof process.send === 'function' && process.send('子进程mine执行完毕');
|
||||||
};
|
};
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
|||||||
Reference in New Issue
Block a user