-
Notifications
You must be signed in to change notification settings - Fork 108
feat: optimize process #1355
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: optimize process #1355
Conversation
Summary of ChangesHello @hwbrzzl, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors and enhances the process execution capabilities, making them more user-friendly and robust. It streamlines the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces optimizations and new features to the process package, notably adding a loading spinner for running processes. It also refactors the Run method to encapsulate errors within the Result object, simplifying its signature. Additionally, a file copy utility is added.
My review focuses on a few critical issues that could lead to panics or incorrect behavior, such as a potential nil pointer dereference and inconsistent error handling. I've also provided suggestions to improve the robustness of a new file utility and its corresponding test. Overall, the changes are a good step forward, and the identified critical issues should be addressed.
| baseProviders := app.getBaseServiceProviders() | ||
| app.providerRepository.Add(baseProviders) | ||
| app.providerRepository.Register(app) | ||
| app.providerRepository.Boot(app) |
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.
Boot base service providers after all service providers are registered.
| } | ||
|
|
||
| exitCode := getExitCode(finalCmd, waitErr) | ||
| break |
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.
The pipeline should be broken if a command failed.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1355 +/- ##
==========================================
+ Coverage 70.15% 70.60% +0.45%
==========================================
Files 281 286 +5
Lines 17180 17612 +432
==========================================
+ Hits 12052 12435 +383
- Misses 4614 4652 +38
- Partials 514 525 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/gemini review |
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.
Code Review
This is an excellent pull request that significantly improves the ergonomics and functionality of the process package. The change to the Run() method signature, encapsulating errors within the Result object, simplifies the API for consumers. The new WithSpinner feature is a great UX enhancement for long-running commands. Furthermore, the fixes addressing pipeline interruption on failure and the race condition in the process pool are crucial for correctness and robustness. The new file.Copy utility is also a welcome addition. The code is well-structured, and the changes are well-tested. I've included a few minor suggestions to enhance consistency in testing and error handling.
krishankumar01
left a comment
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.
Just a few suggestions
|
|
||
| var resultsWg sync.WaitGroup | ||
| var workersWg sync.WaitGroup | ||
| var startsWg sync.WaitGroup |
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 think this looks good, but when I checked start method again, I noticed a major issue. Even if we set a concurrency limit, it still spawns all the processes. So we might need to change the RunningPool implementation. We can optimize this in a different PR.
Example:
builder := NewPool().Concurrency(1)
start := time.Now()
rp, err := builder.Pool(func(p contractsprocess.Pool) {
p.Command("sleep", "1").As("job1")
p.Command("sleep", "1").As("job2")
}).Start()
assert.NoError(t, err) // ideally this should take more than 2 second but it will finish in ~1secThere 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.
Good catch
| func (r *PoolBuilder) Run() (map[string]contractsprocess.Result, error) { | ||
| return r.run(r.poolConfigurer) | ||
| run, err := r.start(r.poolConfigurer) | ||
| if err != nil { |
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.
Do we need to follow a similar syntax here? That is, should we return an error as part of RunningPool, even though the error might be more contextual or related to just process start?
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.
Yes, I also considered this. But given it's map[string]contractsprocess.Result, it's a bit strange to initiate the map when error != nil. So I kept the error here.
|
@krishankumar01 Thanks for your review, done. PTAL. |
krishankumar01
left a comment
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.
Great 👍 LGTM
📑 Description
resultanderrorsimultaneously.After the optimization, it will be simpler:
WithSpinnerfunction to show a spinner when running, and the message can be customized.Use the default message:
Use the custom message:
file.Copy()function.✅ Checks