-
-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Add lifecycle hooks for nitric. #237
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
Conversation
|
Will rebase on: #238 when merged |
8efccb1 to
6705621
Compare
Co-authored-by: Ryan Cartwright <[email protected]>
Co-authored-by: Ryan Cartwright <[email protected]>
|
Current usage now: import { Lifecycle } from "@nitric/sdk"
Lifecycle.whenCollecting(() => {
});
Lifecycle.whenRunning(() => {
});
Lifecycle.isRunning();
Lifecycle.isCollecting(); |
|
It looks like LifecycleStage isn't being exported, which is causing methods like is and when to be unusable. Additionally, I was wondering if you could add descriptions to those lifecycle-related methods—I'm trying to understand the purpose behind methods like isCollecting and whenCollecting, but it's not entirely clear from the current code. One more thing: it would be helpful to have a way to check if something is running locally when using nitric start. Happy to create a formal issue for this if that’s preferred—just let me know! Thanks 🙏 |
|
Hey @AdzeB, Thanks for the feedback, I've started a quick PR to export the stages enum #239 we can add to this if I've missed something. For the descriptions, did you want those in the code like doc comments or in the documentation site? We were thinking of putting the details and use cases in the docs site, but happy to update the SDK comments if that's more useful. To give you the details in the meantime, Nitric runs in essentially 3 modes: Running Locally
Collecting (Local or on a CI/CD server)During Running Deployed/In the CloudThis is when an environment has been deployed; handling real requests, etc. Since typically running locally or in the cloud behave similarly, we group those into the These methods were added as a convenient way to execute custom code or change behavior in just one mode. For example, you might want to perform certain logging during collection, but not when running. Or you might want to change the way you connect to your database locally, but not in the cloud. The if (Lifecycle.isCollecting()) {
// do something only during collection
}The Lifecycle.whenCollecting(() => {
// do something only during collection
}) |
|
Thanks so much for the quick response and the PR @jyecusch — really appreciate it! Regarding the descriptions, I was mainly referring to in-code doc comments so that when hovering over the methods in an editor, users can quickly understand what each one does. That said, having a more detailed explanation on the docs site as well would definitely be helpful, especially for new users. The breakdown you shared makes everything much clearer — I understand the purpose of the lifecycle methods now. Thanks again for taking the time to explain it! |
A proposal for lifecycle hooks in the nitric runtime sdks.
Happy to update the naming to whatever we like. Implementing in the node-sdk first as this will represent the reference implementation for the other SDKs.