Modified stuff for easyer testing, logging questiondb count in daily stats

This commit is contained in:
mrfry 2021-08-01 11:31:09 +02:00
parent d7b5ad8160
commit cc19b5424b
8 changed files with 11 additions and 40 deletions

View file

@ -87,20 +87,12 @@ export function doALongTask(
})
}
export function initWorkerPool(initData: any): void {
export function initWorkerPool(initData: any): Array<WorkerObj> {
if (workers) {
logger.Log('WORKERS ALREADY EXISTS', logger.GetColor('redbg'))
return
}
workers = []
const factory = {
create: function(index) {
return getAWorker(index, initData)
},
destroy: function(client) {
client.worker.terminate()
},
}
const threadCount = process.env.NS_THREAD_COUNT || os.cpus().length
if (process.env.NS_THREAD_COUNT) {
@ -112,11 +104,13 @@ export function initWorkerPool(initData: any): void {
for (let i = 0; i < threadCount; i++) {
workers.push({
worker: factory.create(i),
worker: getAWorker(i, initData),
index: i,
free: true,
})
}
return workers
}
// ---------------------------------------------------------------------------
@ -169,7 +163,7 @@ function processJob() {
freeWorker.free = true
job.doneEvent.emit('done', res)
})
.catch(function(err) {
.catch(function (err) {
handleWorkerError(freeWorker, err)
})
}