Skip to content

Update spinner API to stop all running spinners#170

Merged
chandrareddyp merged 1 commit intovmware-tanzu:mainfrom
chandrareddyp:update/spinner-signal-api
Apr 10, 2024
Merged

Update spinner API to stop all running spinners#170
chandrareddyp merged 1 commit intovmware-tanzu:mainfrom
chandrareddyp:update/spinner-signal-api

Conversation

@chandrareddyp
Copy link
Copy Markdown
Contributor

@chandrareddyp chandrareddyp commented Mar 7, 2024

What this PR does / why we need it

This PR updates the spinner API to store all spinners and close any that are still active when the user wants to stop the spinner after the command has completed or been interrupted. This will help ensure all spinners are properly closed.

Use case:

If the user is running tanzu plugin sync, it installs all the required plugins for each context. Assume that it has installed a few plugins, and now the user wants to terminate the command with Ctrl+C. In this case, the API should stop the current spinner and also check for any other active spinners and terminate them as well. This new API helps handle these types of use cases.

Which issue(s) this PR fixes

Fixes #

Describe testing done for PR

Release note

The spinner API has been updated to track all active spinners and stop them when the command ends or is terminated by the user.

Additional information

Special notes for your reviewer

@chandrareddyp chandrareddyp requested a review from a team as a code owner March 7, 2024 21:34
@chandrareddyp chandrareddyp force-pushed the update/spinner-signal-api branch from 3d98733 to 1863117 Compare March 11, 2024 10:45
Comment on lines +192 to +204
for _, s := range spinners {
if s != nil {
if s.GetErrorText() != "" {
s.SetFinalText(s.GetErrorText(), log.LogTypeERROR)
}
if ows.spinner != nil && ows.spinner.Active() {
ows.spinner.Stop()
if ows.spinnerFinalText != "" {
fmt.Fprintln(ows.out)
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should not be updating this function. This function is to stop specific spinner and should be kept as it is.

We should implement a separate public API like StopAllSpinners (or something similar) which invokes StopSpinner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The API consumer may confuse that why should he call StopAllSpinners as he started a single spinner! If we give a option StopSpinner API then they may use just StopSpinner API instead of StopAllSpinners.

Copy link
Copy Markdown
Contributor

@anujc25 anujc25 Mar 19, 2024

Choose a reason for hiding this comment

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

@chandrareddyp users will not have access to the created outputwriterspinner object while handling the interrupt and hence this cannot be even invoked.

TPR does need to provide an API to stop all spinner objects because TPR can keep track of all open spinner and close them when needed. The way it is implemented today, It does not make much sense to close all spinners by invoking some random spinner object's StopSpinner API.

@anujc25
Copy link
Copy Markdown
Contributor

anujc25 commented Mar 15, 2024

Can you update the PR title and PR description?

@chandrareddyp chandrareddyp changed the title Update spinner API to catch OS signals Update spinner API to stop all running spinners Mar 19, 2024
@chandrareddyp
Copy link
Copy Markdown
Contributor Author

Can you update the PR title and PR description?

Updated

Comment thread component/output_spinner.go Outdated
Copy link
Copy Markdown
Contributor

@anujc25 anujc25 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

Comment thread component/output_spinner.go
@anujc25
Copy link
Copy Markdown
Contributor

anujc25 commented Mar 22, 2024

Please add a release note for this PR as well.

Copy link
Copy Markdown
Contributor

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

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

The code LGTM but could you put in the PR description what scenario we are trying to address? I believe it is for interrupts, right? An example of how this would be used would help. Currently, it is hard to see the added benefit of this new function.

@chandrareddyp chandrareddyp force-pushed the update/spinner-signal-api branch 2 times, most recently from 6f68d37 to 1b66137 Compare April 10, 2024 16:33
@chandrareddyp chandrareddyp force-pushed the update/spinner-signal-api branch from 1b66137 to 3f3b1dc Compare April 10, 2024 16:35
@chandrareddyp chandrareddyp merged commit 72cfcba into vmware-tanzu:main Apr 10, 2024
@marckhouzam marckhouzam added this to the v1.3.0 milestone Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants