hippofish/packages/backend/src/boot/worker.ts
syuilo 7e89e70934
enhance(server): separate job queue process (#9662)
* enhance(server): separate job queue process

* add commands for build with swc
2023-01-21 14:09:01 +09:00

26 lines
791 B
TypeScript

import cluster from 'node:cluster';
import { NestFactory } from '@nestjs/core';
import { ChartManagementService } from '@/core/chart/ChartManagementService.js';
import { QueueProcessorService } from '@/queue/QueueProcessorService.js';
import { NestLogger } from '@/NestLogger.js';
import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js';
/**
* Init worker process
*/
export async function workerMain() {
const jobQueue = await NestFactory.createApplicationContext(QueueProcessorModule, {
logger: new NestLogger(),
});
jobQueue.enableShutdownHooks();
// start job queue
jobQueue.get(QueueProcessorService).start();
jobQueue.get(ChartManagementService).start();
if (cluster.isWorker) {
// Send a 'ready' message to parent process
process.send!('ready');
}
}