Skip to content

Commit

Permalink
Optimize branch delete to avoid too many 404 (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 committed Aug 15, 2023
1 parent 8b9b260 commit 11556aa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
27 changes: 3 additions & 24 deletions internal/cli/branch/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ package branch

import (
"fmt"
"strings"
"time"

"tidbcloud-cli/internal"
"tidbcloud-cli/internal/config"
"tidbcloud-cli/internal/flag"
Expand Down Expand Up @@ -149,27 +146,9 @@ func DeleteCmd(h *internal.Helper) *cobra.Command {
if err != nil {
return errors.Trace(err)
}

ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
timer := time.After(2 * time.Minute)
for {
select {
case <-timer:
return errors.New("timeout waiting for deleting branch, please check status on dashboard")
case <-ticker.C:
_, err := d.GetBranch(branchApi.NewGetBranchParams().
WithClusterID(clusterID).
WithBranchID(branchID))
if err != nil {
if strings.Contains(err.Error(), "404") {
fmt.Fprintln(h.IOStreams.Out, color.GreenString("branch %s deleted", branchID))
return nil
}
return errors.Trace(err)
}
}
}
// print success for delete branch is a sync operation
fmt.Fprintln(h.IOStreams.Out, color.GreenString("branch %s deleted", branchID))
return nil
},
}

Expand Down
4 changes: 0 additions & 4 deletions internal/cli/branch/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package branch

import (
"bytes"
"errors"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -61,9 +60,6 @@ func (suite *DeleteBranchSuite) TestDeleteBranchArgs() {
suite.mockClient.On("DeleteBranch", branchApi.NewDeleteBranchParams().
WithBranchID(branchID).WithClusterID(clusterID)).
Return(&branchApi.DeleteBranchOK{}, nil)
suite.mockClient.On("GetBranch", branchApi.NewGetBranchParams().
WithBranchID(branchID).WithClusterID(clusterID)).
Return(nil, errors.New("404"))

tests := []struct {
name string
Expand Down

0 comments on commit 11556aa

Please sign in to comment.