我正在尝试为 NestJS 创建一个“worker”,它基本上聚合来自多个数据源的数据。由于我将此工作程序部署到 Kubernetes 集群中,因此我不需要启动 NestJS 内部 HTTP 服务器,但是,调度程序不会在没有app.listen
.
主要.ts:
async function bootstrap() {
const app = await NestFactory.create(WorkerModule);
await app.listen(3030); // <-- I would like to delete this
}
bootstrap();
Run Code Online (Sandbox Code Playgroud)
工作模块.ts
@Module({
imports: [
ScheduleModule.forRoot(),
],
providers: [
// Scrappers
DataScrapper,
],
})
export class WorkerModule {}
Run Code Online (Sandbox Code Playgroud)
数据抓取器.ts
@Injectable()
export class DataScrapper {
@Interval(1000)
async sync() {
console.log('fetching...');
}
}
Run Code Online (Sandbox Code Playgroud)