Logging: log syncCount and be less scary

This commit is contained in:
Tim Hockin 2023-10-13 13:36:04 -07:00
parent 8fa652dafa
commit b69d0f3bac
1 changed files with 5 additions and 5 deletions

10
main.go
View File

@ -771,7 +771,7 @@ func main() {
} }
failCount := 0 failCount := 0
firstLoop := true syncCount := uint64(0)
for { for {
start := time.Now() start := time.Now()
ctx, cancel := context.WithTimeout(context.Background(), *flSyncTimeout) ctx, cancel := context.WithTimeout(context.Background(), *flSyncTimeout)
@ -789,7 +789,7 @@ func main() {
// this might have been called before, but also might not have // this might have been called before, but also might not have
setRepoReady() setRepoReady()
// We treat the first loop as a sync, including sending hooks. // We treat the first loop as a sync, including sending hooks.
if changed || firstLoop { if changed || syncCount == 0 {
if absTouchFile != "" { if absTouchFile != "" {
if err := touch(absTouchFile); err != nil { if err := touch(absTouchFile); err != nil {
log.Error(err, "failed to touch touch-file", "path", absTouchFile) log.Error(err, "failed to touch touch-file", "path", absTouchFile)
@ -807,7 +807,7 @@ func main() {
} else { } else {
updateSyncMetrics(metricKeyNoOp, start) updateSyncMetrics(metricKeyNoOp, start)
} }
firstLoop = false syncCount++
// Clean up old worktree(s) and run GC. // Clean up old worktree(s) and run GC.
if err := git.cleanup(ctx); err != nil { if err := git.cleanup(ctx); err != nil {
@ -852,7 +852,7 @@ func main() {
log.DeleteErrorFile() log.DeleteErrorFile()
} }
log.V(3).Info("next sync", "waitTime", flPeriod.String()) log.V(3).Info("next sync", "waitTime", flPeriod.String(), "syncCount", syncCount)
cancel() cancel()
// Sleep until the next sync. If syncSig is set then the sleep may // Sleep until the next sync. If syncSig is set then the sleep may
@ -1076,7 +1076,7 @@ func (git *repoSync) initRepo(ctx context.Context) error {
// the contents rather than the dir itself, because a common use-case // the contents rather than the dir itself, because a common use-case
// is to have a volume mounted at git.root, which makes removing it // is to have a volume mounted at git.root, which makes removing it
// impossible. // impossible.
git.log.V(0).Info("repo directory failed checks or was empty", "path", git.root) git.log.V(0).Info("repo directory was empty or failed checks", "path", git.root)
if err := removeDirContents(git.root, git.log); err != nil { if err := removeDirContents(git.root, git.log); err != nil {
return fmt.Errorf("can't wipe unusable root directory: %w", err) return fmt.Errorf("can't wipe unusable root directory: %w", err)
} }