fix: handle scheduler pool size of 1 as a fixed pool

pull/8104/head
NGPixel 1 week ago
parent a0f47bc3be
commit 0cfed7e651
No known key found for this signature in database

@ -1,4 +1,4 @@
import { DynamicThreadPool } from 'poolifier' import { DynamicThreadPool, FixedThreadPool } from 'poolifier'
import os from 'node:os' import os from 'node:os'
import fs from 'node:fs/promises' import fs from 'node:fs/promises'
import path from 'node:path' import path from 'node:path'
@ -69,7 +69,7 @@ export interface AddJobOptions {
} }
export default { export default {
workerPool: null as DynamicThreadPool<any, boolean> | null, workerPool: null as FixedThreadPool<any, boolean> | null,
pubsubClient: null as PoolClient | null, pubsubClient: null as PoolClient | null,
maxWorkers: 1, maxWorkers: 1,
activeWorkers: 0, activeWorkers: 0,
@ -86,16 +86,18 @@ export default {
this.maxWorkers = 1 this.maxWorkers = 1
} }
WIKI.logger.info(`Initializing Worker Pool (Limit: ${this.maxWorkers})...`) WIKI.logger.info(`Initializing Worker Pool (Limit: ${this.maxWorkers})...`)
this.workerPool = new DynamicThreadPool( const poolFile = path.join(WIKI.SERVERPATH, 'worker.ts')
1, const poolOptions = {
this.maxWorkers, errorHandler: (err: Error) => WIKI.logger.warn(err),
path.join(WIKI.SERVERPATH, 'worker.ts'), exitHandler: () => WIKI.logger.debug('A worker has gone offline.'),
{ onlineHandler: () => WIKI.logger.debug('New worker is online.')
errorHandler: (err: Error) => WIKI.logger.warn(err), }
exitHandler: () => WIKI.logger.debug('A worker has gone offline.'), // -> A dynamic pool refuses a minimum equal to its maximum, which is what a single-CPU host
onlineHandler: () => WIKI.logger.debug('New worker is online.') // (or `workers: 1`) asks for. There is nothing to grow there, so it is a fixed pool of one.
} this.workerPool =
) this.maxWorkers > 1
? new DynamicThreadPool(1, this.maxWorkers, poolFile, poolOptions)
: new FixedThreadPool(1, poolFile, poolOptions)
this.tasks = {} this.tasks = {}
for (const f of await fs.readdir(path.join(WIKI.SERVERPATH, 'tasks/simple'))) { for (const f of await fs.readdir(path.join(WIKI.SERVERPATH, 'tasks/simple'))) {
const taskName = camelCase(f.replace(/\.[jt]s$/, '')) const taskName = camelCase(f.replace(/\.[jt]s$/, ''))

Loading…
Cancel
Save