mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
lib: Print nicely rounded durations (#6756)
This commit is contained in:
parent
4812fd3ec1
commit
8cf9d91ed4
@ -827,7 +827,7 @@ func (db *Lowlevel) loadMetadataTracker(folder string) *metadataTracker {
|
||||
}
|
||||
|
||||
if age := time.Since(meta.Created()); age > db.recheckInterval {
|
||||
l.Infof("Stored folder metadata for %q is %v old; recalculating", folder, age)
|
||||
l.Infof("Stored folder metadata for %q is %v old; recalculating", folder, util.NiceDurationString(age))
|
||||
return db.getMetaAndCheck(folder)
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/scanner"
|
||||
"github.com/syncthing/syncthing/lib/stats"
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
"github.com/syncthing/syncthing/lib/util"
|
||||
"github.com/syncthing/syncthing/lib/watchaggregator"
|
||||
|
||||
"github.com/thejerf/suture"
|
||||
@ -330,7 +331,7 @@ func (f *folder) pull() (success bool) {
|
||||
|
||||
// Pulling failed, try again later.
|
||||
delay := f.pullPause + time.Since(startTime)
|
||||
l.Infof("Folder %v isn't making sync progress - retrying in %v.", f.Description(), delay.Truncate(time.Second))
|
||||
l.Infof("Folder %v isn't making sync progress - retrying in %v.", f.Description(), util.NiceDurationString(delay))
|
||||
f.pullFailTimer.Reset(delay)
|
||||
return false
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/sync"
|
||||
|
||||
@ -314,3 +315,19 @@ func CallWithContext(ctx context.Context, fn func() error) error {
|
||||
return ctx.Err()
|
||||
}
|
||||
}
|
||||
|
||||
func NiceDurationString(d time.Duration) string {
|
||||
switch {
|
||||
case d > 24*time.Hour:
|
||||
d = d.Round(time.Hour)
|
||||
case d > time.Hour:
|
||||
d = d.Round(time.Minute)
|
||||
case d > time.Minute:
|
||||
d = d.Round(time.Second)
|
||||
case d > time.Second:
|
||||
d = d.Round(time.Millisecond)
|
||||
case d > time.Millisecond:
|
||||
d = d.Round(time.Microsecond)
|
||||
}
|
||||
return d.String()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user