cmd: refactor --retries and --retries-sleep to global config
This change moves the --retries and --retries-sleep flags/variables from cmd to config (consistent with --low-level-retries), so that they can be more easily referenced from subcommands.
This commit is contained in:
parent
b14269fd23
commit
407a0f3733
3 changed files with 20 additions and 18 deletions
19
cmd/cmd.go
19
cmd/cmd.go
|
@ -52,8 +52,6 @@ var (
|
||||||
statsInterval = flags.DurationP("stats", "", time.Minute*1, "Interval between printing stats, e.g. 500ms, 60s, 5m (0 to disable)", "Logging")
|
statsInterval = flags.DurationP("stats", "", time.Minute*1, "Interval between printing stats, e.g. 500ms, 60s, 5m (0 to disable)", "Logging")
|
||||||
dataRateUnit = flags.StringP("stats-unit", "", "bytes", "Show data rate in stats as either 'bits' or 'bytes' per second", "Logging")
|
dataRateUnit = flags.StringP("stats-unit", "", "bytes", "Show data rate in stats as either 'bits' or 'bytes' per second", "Logging")
|
||||||
version bool
|
version bool
|
||||||
retries = flags.IntP("retries", "", 3, "Retry operations this many times if they fail", "Config")
|
|
||||||
retriesInterval = flags.DurationP("retries-sleep", "", 0, "Interval between retrying operations if they fail, e.g. 500ms, 60s, 5m (0 to disable)", "Config")
|
|
||||||
// Errors
|
// Errors
|
||||||
errorCommandNotFound = errors.New("command not found")
|
errorCommandNotFound = errors.New("command not found")
|
||||||
errorUncategorized = errors.New("uncategorized error")
|
errorUncategorized = errors.New("uncategorized error")
|
||||||
|
@ -253,7 +251,7 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
||||||
stopStats = StartStats()
|
stopStats = StartStats()
|
||||||
}
|
}
|
||||||
SigInfoHandler()
|
SigInfoHandler()
|
||||||
for try := 1; try <= *retries; try++ {
|
for try := 1; try <= ci.Retries; try++ {
|
||||||
cmdErr = f()
|
cmdErr = f()
|
||||||
cmdErr = fs.CountError(cmdErr)
|
cmdErr = fs.CountError(cmdErr)
|
||||||
lastErr := accounting.GlobalStats().GetLastError()
|
lastErr := accounting.GlobalStats().GetLastError()
|
||||||
|
@ -262,7 +260,7 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
||||||
}
|
}
|
||||||
if !Retry || !accounting.GlobalStats().Errored() {
|
if !Retry || !accounting.GlobalStats().Errored() {
|
||||||
if try > 1 {
|
if try > 1 {
|
||||||
fs.Errorf(nil, "Attempt %d/%d succeeded", try, *retries)
|
fs.Errorf(nil, "Attempt %d/%d succeeded", try, ci.Retries)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -282,15 +280,15 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lastErr != nil {
|
if lastErr != nil {
|
||||||
fs.Errorf(nil, "Attempt %d/%d failed with %d errors and: %v", try, *retries, accounting.GlobalStats().GetErrors(), lastErr)
|
fs.Errorf(nil, "Attempt %d/%d failed with %d errors and: %v", try, ci.Retries, accounting.GlobalStats().GetErrors(), lastErr)
|
||||||
} else {
|
} else {
|
||||||
fs.Errorf(nil, "Attempt %d/%d failed with %d errors", try, *retries, accounting.GlobalStats().GetErrors())
|
fs.Errorf(nil, "Attempt %d/%d failed with %d errors", try, ci.Retries, accounting.GlobalStats().GetErrors())
|
||||||
}
|
}
|
||||||
if try < *retries {
|
if try < ci.Retries {
|
||||||
accounting.GlobalStats().ResetErrors()
|
accounting.GlobalStats().ResetErrors()
|
||||||
}
|
}
|
||||||
if *retriesInterval > 0 {
|
if ci.RetriesInterval > 0 {
|
||||||
time.Sleep(*retriesInterval)
|
time.Sleep(ci.RetriesInterval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stopStats()
|
stopStats()
|
||||||
|
@ -339,7 +337,6 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolveExitCode(cmdErr)
|
resolveExitCode(cmdErr)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckArgs checks there are enough arguments and prints a message if not
|
// CheckArgs checks there are enough arguments and prints a message if not
|
||||||
|
@ -554,7 +551,7 @@ func AddBackendFlags() {
|
||||||
} else {
|
} else {
|
||||||
fs.Errorf(nil, "Not adding duplicate flag --%s", name)
|
fs.Errorf(nil, "Not adding duplicate flag --%s", name)
|
||||||
}
|
}
|
||||||
//flag.Hidden = true
|
// flag.Hidden = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ type ConfigInfo struct {
|
||||||
MaxDeleteSize SizeSuffix
|
MaxDeleteSize SizeSuffix
|
||||||
TrackRenames bool // Track file renames.
|
TrackRenames bool // Track file renames.
|
||||||
TrackRenamesStrategy string // Comma separated list of strategies used to track renames
|
TrackRenamesStrategy string // Comma separated list of strategies used to track renames
|
||||||
|
Retries int // High-level retries
|
||||||
|
RetriesInterval time.Duration // --retries-sleep
|
||||||
LowLevelRetries int
|
LowLevelRetries int
|
||||||
UpdateOlder bool // Skip files that are newer on the destination
|
UpdateOlder bool // Skip files that are newer on the destination
|
||||||
NoGzip bool // Disable compression
|
NoGzip bool // Disable compression
|
||||||
|
@ -171,6 +173,7 @@ func NewConfig() *ConfigInfo {
|
||||||
c.DeleteMode = DeleteModeDefault
|
c.DeleteMode = DeleteModeDefault
|
||||||
c.MaxDelete = -1
|
c.MaxDelete = -1
|
||||||
c.MaxDeleteSize = SizeSuffix(-1)
|
c.MaxDeleteSize = SizeSuffix(-1)
|
||||||
|
c.Retries = 3
|
||||||
c.LowLevelRetries = 10
|
c.LowLevelRetries = 10
|
||||||
c.MaxDepth = -1
|
c.MaxDepth = -1
|
||||||
c.DataRateUnit = "bytes"
|
c.DataRateUnit = "bytes"
|
||||||
|
|
|
@ -75,6 +75,8 @@ func AddFlags(ci *fs.ConfigInfo, flagSet *pflag.FlagSet) {
|
||||||
flags.FVarP(flagSet, &ci.MaxDeleteSize, "max-delete-size", "", "When synchronizing, limit the total size of deletes", "Sync")
|
flags.FVarP(flagSet, &ci.MaxDeleteSize, "max-delete-size", "", "When synchronizing, limit the total size of deletes", "Sync")
|
||||||
flags.BoolVarP(flagSet, &ci.TrackRenames, "track-renames", "", ci.TrackRenames, "When synchronizing, track file renames and do a server-side move if possible", "Sync")
|
flags.BoolVarP(flagSet, &ci.TrackRenames, "track-renames", "", ci.TrackRenames, "When synchronizing, track file renames and do a server-side move if possible", "Sync")
|
||||||
flags.StringVarP(flagSet, &ci.TrackRenamesStrategy, "track-renames-strategy", "", ci.TrackRenamesStrategy, "Strategies to use when synchronizing using track-renames hash|modtime|leaf", "Sync")
|
flags.StringVarP(flagSet, &ci.TrackRenamesStrategy, "track-renames-strategy", "", ci.TrackRenamesStrategy, "Strategies to use when synchronizing using track-renames hash|modtime|leaf", "Sync")
|
||||||
|
flags.IntVarP(flagSet, &ci.Retries, "retries", "", 3, "Retry operations this many times if they fail", "Config")
|
||||||
|
flags.DurationVarP(flagSet, &ci.RetriesInterval, "retries-sleep", "", 0, "Interval between retrying operations if they fail, e.g. 500ms, 60s, 5m (0 to disable)", "Config")
|
||||||
flags.IntVarP(flagSet, &ci.LowLevelRetries, "low-level-retries", "", ci.LowLevelRetries, "Number of low level retries to do", "Config")
|
flags.IntVarP(flagSet, &ci.LowLevelRetries, "low-level-retries", "", ci.LowLevelRetries, "Number of low level retries to do", "Config")
|
||||||
flags.BoolVarP(flagSet, &ci.UpdateOlder, "update", "u", ci.UpdateOlder, "Skip files that are newer on the destination", "Copy")
|
flags.BoolVarP(flagSet, &ci.UpdateOlder, "update", "u", ci.UpdateOlder, "Skip files that are newer on the destination", "Copy")
|
||||||
flags.BoolVarP(flagSet, &ci.UseServerModTime, "use-server-modtime", "", ci.UseServerModTime, "Use server modified time instead of object metadata", "Config")
|
flags.BoolVarP(flagSet, &ci.UseServerModTime, "use-server-modtime", "", ci.UseServerModTime, "Use server modified time instead of object metadata", "Config")
|
||||||
|
|
Loading…
Reference in a new issue