temporalio / sdk-typescript

Temporal TypeScript SDK
Other
499 stars 94 forks source link

[Bug] NestJS integration, app/worker hot reloading error #1437

Open tiberiu89 opened 1 month ago

tiberiu89 commented 1 month ago

I'm using nestjs-temporal package, but I assume it would be the same with the nestjs typescript samples provided(if using nest start worker --watch). Everything is good at first run, but after code changes and nestjs reloading, the worker cannot restart, saying address port is already in use(3000). Does anyone experienced this? Any ideas of a workaround would be appreciated. Manually restarting app is quite annoying.

tiberiu89 commented 1 month ago

Maybe to answer my question, I found one possible alternative We can split a nestjs app, by creating a separate entry point and main module that would create standalone app(no http server). Then, edit the nest-cli.json to register this as a separate app. Code and modules can still be shared.

import { NestFactory } from '@nestjs/core';
import { MainRuntimeModule } from './runtime.module';

async function bootstrap() {
  await NestFactory.createApplicationContext(MainRuntimeModule);
}

bootstrap();

We load the module that registers workers only here + everything you need from the main codebase.