From 62750317d4adafbedf5245d968aa025dfe6b47a8 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 25 Apr 2015 23:08:44 -0700 Subject: [PATCH] Add proper retry() mechanisms and print that in Magenta color --- cmd-cp.go | 1 - cmd-ls.go | 15 ++++++++++++--- cmd-mb.go | 7 ++----- pkg/console/console.go | 6 +++++- pkg/console/themes.go | 3 +++ 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/cmd-cp.go b/cmd-cp.go index fe490479..09033a7a 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -86,7 +86,6 @@ func runCopyCmd(ctx *cli.Context) { return } err = doCopyCmd(mcClientManager{}, sourceURLConfigMap, targetURLConfigMap) - err = iodine.New(err, nil) if err != nil { log.Debug.Println(err) console.Fatalf("Failed to copy from source [%s] to target %s. Reason: [%s].\n", sourceURL, targetURLs, iodine.ToError(err)) diff --git a/cmd-ls.go b/cmd-ls.go index d10aa758..bc42b7ea 100644 --- a/cmd-ls.go +++ b/cmd-ls.go @@ -55,7 +55,6 @@ func doList(clnt client.Client, targetURL string) error { } printItem(itemCh.Item.Time, itemCh.Item.Size, itemCh.Item.Name, itemCh.Item.FileType) } - if err != nil { return iodine.New(err, map[string]string{"Target": targetURL}) } @@ -98,7 +97,7 @@ func runListCmd(ctx *cli.Context) { err = iodine.New(err, nil) if err != nil { log.Debug.Println(err) - console.Fatalf("Failed to list [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err)) + console.Fatalln("Failed to list [%s]. Reason: [%s].\n", targetURL, iodine.ToError(err)) } } } @@ -108,5 +107,15 @@ func doListCmd(manager clientManager, targetURL string, targetConfig *hostConfig if err != nil { return iodine.New(err, map[string]string{"Target": targetURL}) } - return doList(clnt, targetURL) + err = doList(clnt, targetURL) + for i := 0; i < globalMaxRetryFlag && err != nil && isValidRetry(err); i++ { + fmt.Println(console.Retry("Retrying ... %d", i)) + // Progressively longer delays + time.Sleep(time.Duration(i*i) * time.Second) + err = doList(clnt, targetURL) + } + if err != nil { + return iodine.New(err, nil) + } + return nil } diff --git a/cmd-mb.go b/cmd-mb.go index b7940a3a..66cc4624 100644 --- a/cmd-mb.go +++ b/cmd-mb.go @@ -85,14 +85,11 @@ func doMakeBucketCmd(manager clientManager, targetURL string, targetConfig *host func doMakeBucket(clnt client.Client, targetURL string) (string, error) { err := clnt.PutBucket("") - if err != nil && isValidRetry(err) { - console.Infof("Retrying ...") - } for i := 0; i < globalMaxRetryFlag && err != nil && isValidRetry(err); i++ { - err = clnt.PutBucket("") - console.Errorf(" %d", i) + fmt.Println(console.Retry("Retrying ... %d", i)) // Progressively longer delays time.Sleep(time.Duration(i*i) * time.Second) + err = clnt.PutBucket("") } if err != nil { err := iodine.New(err, nil) diff --git a/pkg/console/console.go b/pkg/console/console.go index 849a5efc..390edc55 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -78,8 +78,10 @@ var ( Dir = themesDB[currThemeName].Dir.SprintfFunc() // Size - Size("12GB") Size = themesDB[currThemeName].Size.SprintfFunc() - //Time - Time("12 Hours") + // Time - Time("12 Hours") Time = themesDB[currThemeName].Time.SprintfFunc() + // Retry - Retry message number + Retry = themesDB[currThemeName].Retry.SprintfFunc() ) // Theme holds console color scheme @@ -92,6 +94,7 @@ type Theme struct { Time *color.Color File *color.Color Dir *color.Color + Retry *color.Color // Reason *color.Color } @@ -247,6 +250,7 @@ func SetTheme(themeName string) error { File = theme.File.SprintfFunc() Size = theme.Size.SprintfFunc() Time = theme.Time.SprintfFunc() + Retry = theme.Retry.SprintfFunc() mutex.Unlock() diff --git a/pkg/console/themes.go b/pkg/console/themes.go index 0cf82ded..38e01123 100644 --- a/pkg/console/themes.go +++ b/pkg/console/themes.go @@ -28,6 +28,7 @@ var MiniTheme = Theme{ Dir: (color.New(color.FgCyan, color.Bold)), Size: (color.New(color.FgYellow)), Time: (color.New(color.FgGreen)), + Retry: (color.New(color.FgMagenta, color.Bold)), } // WhiteTheme - All white color theme @@ -40,6 +41,7 @@ var WhiteTheme = Theme{ Dir: (color.New(color.FgWhite, color.Bold)), Size: (color.New(color.FgWhite, color.Bold)), Time: (color.New(color.FgWhite, color.Bold)), + Retry: (color.New(color.FgWhite, color.Bold)), } // NoColorTheme - Disables color theme @@ -52,4 +54,5 @@ var NoColorTheme = Theme{ Dir: (color.New()), Size: (color.New()), Time: (color.New()), + Retry: (color.New()), }