make cron get conf.json from main process
parent
1d88824b12
commit
76728c28b5
|
|
@ -7,7 +7,9 @@ module.exports = (s,config,lang) => {
|
||||||
if(config.doCronAsWorker===undefined)config.doCronAsWorker = true;
|
if(config.doCronAsWorker===undefined)config.doCronAsWorker = true;
|
||||||
const startWorker = () => {
|
const startWorker = () => {
|
||||||
const pathToWorkerScript = __dirname + `/cron/worker.js`
|
const pathToWorkerScript = __dirname + `/cron/worker.js`
|
||||||
const workerProcess = new Worker(pathToWorkerScript)
|
const workerProcess = new Worker(pathToWorkerScript,{
|
||||||
|
workerData: config
|
||||||
|
})
|
||||||
workerProcess.on('message',function(data){
|
workerProcess.on('message',function(data){
|
||||||
if(data.time === 'moment()')data.time = moment();
|
if(data.time === 'moment()')data.time = moment();
|
||||||
switch(data.f){
|
switch(data.f){
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ const path = require('path');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
const spawn = require('child_process').spawn;
|
const spawn = require('child_process').spawn;
|
||||||
const { parentPort, isMainThread } = require('worker_threads');
|
const { parentPort, isMainThread, workerData } = require('worker_threads');
|
||||||
const config = require(process.cwd() + '/conf.json')
|
const config = workerData
|
||||||
process.on('uncaughtException', function (err) {
|
process.on('uncaughtException', function (err) {
|
||||||
errorLog('uncaughtException',err);
|
errorLog('uncaughtException',err);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue