-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: add OnStart hook for synchronous startup jobs #2079
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
base: development
Are you sure you want to change the base?
feat: add OnStart hook for synchronous startup jobs #2079
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure why this was changed. As if code using a different logger was added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was building a new docker container, it automatically changes if u run so "go build " kinds of prompts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HeerakKashyap Please reomve these changes. There should be no changes to go.work.sum
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should i update iin readme.md , it would be okay to do so right ? @Umang01-hash |
@HeerakKashyap I think we can update the existing docs or maybe create a new one for the same. Both can work depending upon the content we are sharing. |
- Move OnStart logic to a dedicated, testable method. - Fix all linter issues (deep-exit and cyclomatic complexity). - Add unit tests for success and error cases. - Add comprehensive documentation with a realistic example. - Update the example app to demonstrate a real-world use case.
57c4743
to
8526959
Compare
![]() |
…own on context cancel)
…hyap/gofr into fix/onstart-di-context
kidnly have a look @ccoVeille @Umang01-hash |
The code is in, but I would prefer if the context was not forged twice. Can't we create the gofr.Context before calling startup hooks, then pass it through all the layers as argument up to the place where the gofr.Context is created now? Or would this implies breaking changes,? Or simply too much changes? Please note, it doesn't necessary have to be addressed in this PR. |
Thank you for the suggestion Sir! @ccoVeille I agree that creating the gofr.Context only once and passing it through would be cleaner and more efficient. For this PR, I’ll keep the current approach to avoid introducing breaking changes, but I think this is a great idea for future improvement and can be considered in a dedicated refactor. |
@Umang01-hash sir, kindly run the workflows and let me know is there now any linter errors etc. |
Hey @HeerakKashyap only a few things:
Please do the above changes and we should be ready to go with your PR. |
- Fix dynamic error definition - Fix unused parameters with underscore - Use t.Context() instead of context.Background() - Use assert.NoError instead of assert.Nil
- Fix cuddled return statement in newContextForHooks - Fix cuddled assignment in OnStart test - Remove os.Exit call to resolve deep-exit error
f4882d6
to
9e8bcdf
Compare
@Umang01-hash kidnly , check the changes out |
![]() |
…tainability - Fix err113: Replace dynamic error creation with static error in TestApp_OnStart - Fix gocyclo: Refactor Run() method by extracting helper methods to reduce cyclomatic complexity - Fix ws1: Correct whitespace issues in gofr_test.go and run.go - Add helper methods: handleStartupHooks, startShutdownHandler, startTelemetryIfEnabled, startAllServers - Improve code organization and readability while maintaining functionality
i had to make couple of changes to fix the complexity issue , kindly see if this works @Umang01-hash |
- Fix err113: Move error variable to package level to avoid dynamic error creation - Fix error-naming: Rename hookFailedErr to errHookFailed following Go naming conventions - Fix whitespace: Remove unnecessary blank line before app assignment - All linting issues in modified files are now resolved
@Umang01-hash So this PR is ready to get merged ? |
@Umang01-hash CAN U LET me know how can i run linter test locally, if there's some application in Golang for running linter tests |
Hey @HeerakKashyap! You can follow this command to install linter : go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1 then export it's path and you can run the linters locally using |
okay Sir, let me do this then i'll let u know |
@Umang01-hash Code quality tests are passed, what's next ? |
all linter issues are solved, I tested it locally |
@Umang01-hash . KINDLY REVIEW |
Description:
OnStart
hook for the GoFr framework, allowing users to register synchronous startup jobs that execute before the server starts.*gofr.Context
with all DI-managed services, as requested by maintainers.Testing:
Fixes #1833
Let me know if you want to add or change anything, or if you need help attaching screenshots or filling out the checklist!