maxBuffer
This commit is contained in:
@@ -17,10 +17,34 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Fund = require('../modules/fund/fund.model');
|
||||
const exec = require('child_process').exec;
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const mock = {
|
||||
touch: () => {mylog.info('-----------------\n');},
|
||||
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) {
|
||||
mylog.info('[Schedule Job] 矿晶确认程序开始执行......');
|
||||
@@ -49,21 +73,8 @@ async function confirm (job = mock, done = mock) {
|
||||
}
|
||||
|
||||
async function mineJob (job = mock, done = mock) {
|
||||
const rl = exec('node ./src/jobs/mine.js');
|
||||
rl.stderr.on('data', function (data) {
|
||||
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('挖矿程序执行完毕');
|
||||
});
|
||||
watcher.emit('startMine');
|
||||
return typeof done === 'function' && done('矿晶确认完成');
|
||||
}
|
||||
|
||||
const jobs = [
|
||||
|
||||
@@ -5,7 +5,6 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const prettyStdOut = new PrettyStream();
|
||||
prettyStdOut.pipe(process.stdout);
|
||||
|
||||
if (!fs.existsSync('minelog')) {
|
||||
fs.mkdirSync('minelog');
|
||||
@@ -163,17 +162,14 @@ async function mine (job = mock, done = mock) {
|
||||
value: -1
|
||||
}
|
||||
});
|
||||
typeof process.send === 'function' && process.send('tick');
|
||||
}
|
||||
currentIndex += 10;
|
||||
probe.currentIndex = currentIndex;
|
||||
}
|
||||
mylog.info('收益计算分配完成');
|
||||
typeof process.send === 'function' && process.send('tick');
|
||||
await system.findOneAndUpdate({
|
||||
key: 'userIndex4job'
|
||||
}, { $set: { value: 0 } }).exec();
|
||||
typeof process.send === 'function' && process.send('tick');
|
||||
await system.findOneAndUpdate({
|
||||
key: 'mineCount',
|
||||
}, {
|
||||
@@ -181,20 +177,18 @@ async function mine (job = mock, done = mock) {
|
||||
value: 1
|
||||
}
|
||||
}, { upsert: true });
|
||||
typeof process.send === 'function' && process.send('tick');
|
||||
await system.findOneAndUpdate({
|
||||
key: 'lastMine',
|
||||
}, {
|
||||
value: new Date().toISOString()
|
||||
}, { upsert: true });
|
||||
typeof process.send === 'function' && process.send('tick');
|
||||
typeof done === 'function' && done('收益计算分配完成');
|
||||
process.exit();
|
||||
}
|
||||
const probe = {
|
||||
currentIndex: 0
|
||||
};
|
||||
const start = async () => {
|
||||
const start = async (job, done) => {
|
||||
const SysConfig = require('../../configSec');
|
||||
mongoose.set('useCreateIndex', true);
|
||||
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('uncaughtException', beforeExit);
|
||||
process.on('unhandledRejection', beforeExit);
|
||||
mine();
|
||||
typeof process.send === 'function' && process.send('子进程开始执行mine');
|
||||
mine(job, done);
|
||||
typeof process.send === 'function' && process.send('子进程mine执行完毕');
|
||||
};
|
||||
|
||||
start();
|
||||
|
||||
Reference in New Issue
Block a user