index.ts
918 字节
import * as path from 'path'
let job_handlers: any = new Map();
if (global['config'].enable_piscina) {
const Piscina = require('piscina')
const piscina = new Piscina({
filename: path.resolve(__dirname, 'worker.js'),
maxThreads: require('os').cpus().length - 1,
minThreads: 1,
// maxQueue: 1000,
// idleTimeout: 60_000,
// resourceLimits: {
// maxOldGenerationSizeMb: 1024,
// maxYoungGenerationSizeMb: 256,
// stackSizeMb: 4,
// },
});
async function run_task(args) {
return piscina.run(args);
}
run_task({ name: 'get_task_keys' }).then(function (data) {
data.forEach(function (name) {
job_handlers.set(name, (args) => run_task({ name, args }));
})
});
} else {
job_handlers = require('./worker')({ name: 'get_task_list' })
}
export { job_handlers }