mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Adding questions using worker pools
This commit is contained in:
parent
d8695682f7
commit
4681ea3791
5 changed files with 50 additions and 17 deletions
|
@ -585,7 +585,6 @@ const workerTs = (file: string, wkOpts: any) => {
|
|||
|
||||
if (!isMainThread) {
|
||||
const workerIndex = workerData.workerIndex
|
||||
// TODO: check if thread independent
|
||||
|
||||
logger.Log(
|
||||
`[THREAD #${workerIndex}]: Worker ${workerIndex} reporting for duty`
|
||||
|
@ -595,7 +594,11 @@ if (!isMainThread) {
|
|||
if (msg.type === 'work') {
|
||||
const { qdb, subjName, question, questionData } = msg.data
|
||||
const index = msg.index
|
||||
console.log(`[THREAD #${workerIndex}]: staring work on ${index}`)
|
||||
console.log(
|
||||
`[THREAD #${workerIndex}]: staring work${
|
||||
!isNaN(index) ? ` on job index #${index}` : ''
|
||||
}`
|
||||
)
|
||||
|
||||
let searchResult = null
|
||||
try {
|
||||
|
@ -607,12 +610,18 @@ if (!isMainThread) {
|
|||
|
||||
// ONDONE:
|
||||
parentPort.postMessage({
|
||||
msg: `From thread #${workerIndex}: job ${index} done`,
|
||||
msg: `From thread #${workerIndex}: job ${
|
||||
!isNaN(index) ? `#${index}` : ''
|
||||
}done`,
|
||||
workerIndex: workerIndex,
|
||||
result: searchResult,
|
||||
})
|
||||
|
||||
console.log(`[THREAD #${workerIndex}]: Work ${index} done!`)
|
||||
console.log(
|
||||
`[THREAD #${workerIndex}]: Work ${
|
||||
!isNaN(index) ? `#${index}` : ''
|
||||
}done!`
|
||||
)
|
||||
} else if (msg.type === 'update') {
|
||||
if (msg.data.workerIndex !== workerIndex) {
|
||||
// TODO
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue