Add proper retry() mechanisms and print that in Magenta color
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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()),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user