Skip to content
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: graceful shutdown timeout #2422

Merged
merged 10 commits into from Nov 26, 2023

Conversation

Lp-Francois
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #2421

What is the new behavior?

Add a new option gracefulShutdownTimeoutMs that adds a delay to the application shutdown if specified.

If your application requires postponing its shutdown process, this can be done by configuring the `gracefulShutdownTimeoutMs` in the `TerminusModule options`. 
This setting can prove particularly beneficial when working with an orchestrator such as Kubernetes. 
By setting a delay slightly longer than the readiness check interval, you can achieve zero downtime 
when shutting down containers.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@Lp-Francois Lp-Francois changed the title Feat graceful shutdown timeout feat: graceful shutdown timeout Nov 22, 2023
@BrunnerLivio
Copy link
Member

Thanks a lot @Lp-Francois well done!

Lp-Francois and others added 6 commits November 23, 2023 17:25
Co-authored-by: Livio Brunner <livio.brunner.lb1@gmail.com>
Suggestion from @BrunnerLivio during PR review

Co-authored-by: Livio Brunner <livio.brunner.lb1@gmail.com>
Suggestion from @BrunnerLivio during PR review

Co-authored-by: Livio Brunner <livio.brunner.lb1@gmail.com>
Suggestion from @BrunnerLivio during PR review

Co-authored-by: Livio Brunner <livio.brunner.lb1@gmail.com>
…rvice


Suggestion from @BrunnerLivio during PR review

Co-authored-by: Livio Brunner <livio.brunner.lb1@gmail.com>
@Lp-Francois
Copy link
Contributor Author

Requested changes done ✅ @BrunnerLivio

@BrunnerLivio BrunnerLivio merged commit cc3d402 into nestjs:master Nov 26, 2023
11 checks passed
@BrunnerLivio
Copy link
Member

Great job, about to release this!

@Lp-Francois
Copy link
Contributor Author

Nice thanks ✌️

@BrunnerLivio
Copy link
Member

Moved the documentation from the README.md to the NestJS docs.

nestjs/docs.nestjs.com#2908

this.logger.log(
`Awaiting ${this.gracefulShutdownTimeoutMs}ms before shutdown`,
);
await sleep(this.gracefulShutdownTimeoutMs);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrunnerLivio you can just:

import { setTimeout } from 'node:timers/promises';

await setTimeout(this.gracefulShutdownTimeoutMs);

see: https://nodejs.org/api/timers.html#timerspromisessettimeoutdelay-value-options

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BrunnerLivio sorry, wrong mention... the author of the PR is @Lp-Francois

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, didn't know this API exist :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants