-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): add shutdown lifecycle hook to node executor #27354
feat(core): add shutdown lifecycle hook to node executor #27354
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d512cd4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targets
Sent with 💌 from NxCloud. |
To execute application before shutdown events with asynchronous functions and prevent nx shutdown immediately. Espically for NestJS lifecycle events https://docs.nestjs.com/fundamentals/lifecycle-events. fixes nrwl#9237 and nrwl#18037
Thanks @weiliang79 for the PR. I'm just pushing a clean-up on the logic and removing the parts we don't need. |
d74cd1f
to
d512cd4
Compare
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> When the application are received a shutdown signal, the application doesn't execute before shutdown functions and directly shutdown whole application. The situation cannot execute before shutdown functions like [NestJS Lifecycle Events](https://docs.nestjs.com/fundamentals/lifecycle-events) and custom shutdown hooks. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> The application can run shutdown hooks like below output: NX Successfully ran target build for project nest-test (5s) Debugger listening on ws://localhost:9229/e4bd44c0-9a6a-468a-8b46-b6fef1cef1c7 For help, see: https://nodejs.org/en/docs/inspector ``` NX Successfully ran target build for project nest-test (4s) Debugger listening on ws://localhost:9229/75c8449b-43a4-4d8b-88c0-231761d7248c For help, see: https://nodejs.org/en/docs/inspector To exit the process with SIGINT, press Ctrl+C [Nest] 393107 - 08/09/2024, 6:31:26 PM LOG [NestFactory] Starting Nest application... [Nest] 393107 - 08/09/2024, 6:31:26 PM LOG [InstanceLoader] AppModule dependencies initialized +10ms [Nest] 393107 - 08/09/2024, 6:31:26 PM LOG [RoutesResolver] AppController {/api}: +7ms [Nest] 393107 - 08/09/2024, 6:31:26 PM LOG [RouterExplorer] Mapped {/api, GET} route +3ms [Nest] 393107 - 08/09/2024, 6:31:26 PM LOG [NestApplication] Nest application successfully started +2ms [Nest] 393107 - 08/09/2024, 6:31:26 PM LOG 🚀 Application is running on: http://localhost:3000/api [Nest] 393107 - 08/09/2024, 6:31:29 PM LOG onModuleDestroy onModuleDestroy: 5.001s [Nest] 393107 - 08/09/2024, 6:31:34 PM LOG beforeApplicationShutdown SIGINT beforeApplicationShutdown: 5.004s [Nest] 393107 - 08/09/2024, 6:31:39 PM LOG onApplicationShutdown SIGINT onApplicationShutdown: 5.005s NX Process exited with code 130, waiting for changes to restart... ``` ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #9237 and #18037 --------- Co-authored-by: Jack Hsu <jack.hsu@gmail.com> (cherry picked from commit b5a9336)
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
When the application are received a shutdown signal, the application doesn't execute before shutdown functions and directly shutdown whole application. The situation cannot execute before shutdown functions like NestJS Lifecycle Events and custom shutdown hooks.
Expected Behavior
The application can run shutdown hooks like below output:
NX Successfully ran target build for project nest-test (5s)
Debugger listening on ws://localhost:9229/e4bd44c0-9a6a-468a-8b46-b6fef1cef1c7
For help, see: https://nodejs.org/en/docs/inspector
Related Issue(s)
Fixes #9237 and #18037