-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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 ourterms of serviceand privacy statement.We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: onApplicationReady Hook #13806
Comments
+1 support |
I'm not sure about the naming and the role of that hook. I'd need to think more about it. But I can say that maybe we need a more specific name because 'ready' can be interpreted in several ways You can supply a callback already to |
@micaleviskMaybe something like onApplicationInit |
'init' would be confusing because we have |
What about usinghttps://docs.nestjs /techniques/eventsand then awaitapp.listen(...);
awaitapp.get(EventEmitter2).emit(...); Done(?) This gives you full control too |
@kamilmysliwiecI personally already use this approach. It just feels like this functionality should be available out of the box with the rest of the hooks and have similar usage. Without this hook, lifecycle hooks feel incomplete. |
The thing is, |
Yeah, I didn't take those things into account when I came up with the hook name. Naming is not my strong point:) There's a lot to think about here. You guys know better anyway. |
I'm also interested by this feature. I have been using NestJS as my backend framework for years and I'd love to contribute to NestJS.
@kamilmysliwiecI think it would make sense to name the lifecycle "events" related to the methods we use to bootstrap a NestJS app: constapp=awaitNestFactory.create(AppModule);
// Triggers the method `onApplicationCreated` of all `OnApplicationCreated` implementations
awaitapp.listen(...);
// Triggers the method `onApplicationListening` of all `OnApplicationListening` implementations. What do you think of these namings? |
On another subject, I'd like to react to this comment:
I am not a big fan of EventEmitter2 but I have been implementing in by own synchronous event bus (with handlers priority management) in my backends for some time and it would really be awesome if NestJS had an internal event bus we could subscribe to when we need it. |
@SylvainMartyas we can do I still have no ideia about the naming of this |
@micaleviskThank you for your answer. I'm not familiar with the To me, it would be useful to have the following lifecycle events:
About the method Let me know what you think of this. |
Looks good so far but I guess we won't rename nor change/deprecate existing hooks anytime soon |
I was looking into liveness/readiness indicators for Kubernetes (via Terminus). And found some events, such as the proposal here as being required to properly manage the probe states. I also develop Spring Boot apps and there are a lot of comparable patterns provided by that framework. Specifically re: application events, Spring provides a set ofapplication eventsthat include what is being requested here, so that may be useful to compare the definitions they use. A direct use-case for this Ultimately the number ofNest's lifecycle eventsare somewhat finite, but I wonder if producing them via an emitter/filterable listeners as opposed to distinct hook methods could be easier/more scalable? Some related links re: Kubernetes probes: |
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
There are a lot of potential tasks that can be done successfully only after the start of an application (when the app is ready to handle connections).
The
onApplicationBootstrap
triggers beforeawait app.listen()
,so it can't be used for such tasks (correct me if I'm wrong).Describe the solution you'd like
Although this can be easily implemented using events, another good option would be introducing a new hook that triggers after
await app.listen()
.Teachability, documentation, adoption, migration strategy
The hook's name can be
onApplicationReady
oronApplicationStart
.The usage of the hook will be pretty similar to the other hooks:What is the motivation / use case for changing the behavior?
One of the use cases could be webhook subscriptions. When I subscribe to webhooks, the publisher sends me a POST request to verify my webhook callback. It is safer to perform this task after the application is ready to listen for connections.
The text was updated successfully, but these errors were encountered: