Fix off-by-one in max-failures and docs

This commit is contained in:
Tim Hockin 2023-06-15 14:04:23 -07:00
parent b60eef6b30
commit c1afd4d578
3 changed files with 14 additions and 11 deletions

View File

@ -112,7 +112,6 @@ More documentation on specific topics can be [found here](./docs).
## Manual ## Manual
``` ```
GIT-SYNC GIT-SYNC
NAME NAME
@ -266,10 +265,10 @@ OPTIONS
Print this manual and exit. Print this manual and exit.
--max-failures <int>, $GITSYNC_MAX_FAILURES --max-failures <int>, $GITSYNC_MAX_FAILURES
The number of consecutive failures allowed before aborting (the The number of consecutive failures allowed before aborting.
first sync must succeed), Setting this to a negative value will Setting this to a negative value will retry forever. If not
retry forever after the initial sync. If not specified, this specified, this defaults to 0, meaning any sync failure will
defaults to 0, meaning any sync failure will terminate git-sync. terminate git-sync.
--one-time, $GITSYNC_ONE_TIME --one-time, $GITSYNC_ONE_TIME
Exit after one sync. Exit after one sync.

12
main.go
View File

@ -384,7 +384,7 @@ func main() {
"sync on receipt of the specified signal (e.g. SIGHUP)") "sync on receipt of the specified signal (e.g. SIGHUP)")
flMaxFailures := pflag.Int("max-failures", flMaxFailures := pflag.Int("max-failures",
envInt(0, "GITSYNC_MAX_FAILURES", "GIT_SYNC_MAX_FAILURES"), envInt(0, "GITSYNC_MAX_FAILURES", "GIT_SYNC_MAX_FAILURES"),
"the number of consecutive failures allowed before aborting (the first sync must succeed, -1 will retry forever") "the number of consecutive failures allowed before aborting (-1 will retry forever")
flTouchFile := pflag.String("touch-file", flTouchFile := pflag.String("touch-file",
envString("", "GITSYNC_TOUCH_FILE", "GIT_SYNC_TOUCH_FILE"), envString("", "GITSYNC_TOUCH_FILE", "GIT_SYNC_TOUCH_FILE"),
"the path (absolute or relative to --root) to an optional file which will be touched whenever a sync completes (defaults to disabled)") "the path (absolute or relative to --root) to an optional file which will be touched whenever a sync completes (defaults to disabled)")
@ -964,7 +964,7 @@ func main() {
if changed, hash, err := git.SyncRepo(ctx, refreshCreds); err != nil { if changed, hash, err := git.SyncRepo(ctx, refreshCreds); err != nil {
failCount++ failCount++
updateSyncMetrics(metricKeyError, start) updateSyncMetrics(metricKeyError, start)
if *flMaxFailures >= 0 && failCount > *flMaxFailures { if *flMaxFailures >= 0 && failCount >= *flMaxFailures {
// Exit after too many retries, maybe the error is not recoverable. // Exit after too many retries, maybe the error is not recoverable.
log.Error(err, "too many failures, aborting", "failCount", failCount) log.Error(err, "too many failures, aborting", "failCount", failCount)
os.Exit(1) os.Exit(1)
@ -2375,10 +2375,10 @@ OPTIONS
Print this manual and exit. Print this manual and exit.
--max-failures <int>, $GITSYNC_MAX_FAILURES --max-failures <int>, $GITSYNC_MAX_FAILURES
The number of consecutive failures allowed before aborting (the The number of consecutive failures allowed before aborting.
first sync must succeed), Setting this to a negative value will Setting this to a negative value will retry forever. If not
retry forever after the initial sync. If not specified, this specified, this defaults to 0, meaning any sync failure will
defaults to 0, meaning any sync failure will terminate git-sync. terminate git-sync.
--one-time, $GITSYNC_ONE_TIME --one-time, $GITSYNC_ONE_TIME
Exit after one sync. Exit after one sync.

View File

@ -89,6 +89,10 @@ The new name of this flag is shorter and captures the idea that any
non-recoverable error in the sync loop counts as a failure. For backwards non-recoverable error in the sync loop counts as a failure. For backwards
compatibility, `--max-sync-failures` will be used if it is specified. compatibility, `--max-sync-failures` will be used if it is specified.
git-sync v3 demanded that the first sync succeed, regardless of this flag.
git-sync v4 always allows failures up to this maximum, whether it is the first
sync or any other.
### Timeouts: `--timeout` -> `--sync-timeout` ### Timeouts: `--timeout` -> `--sync-timeout`
The old `--timeout` flag took an integer number of seconds as an argument. The The old `--timeout` flag took an integer number of seconds as an argument. The