config: support zrepl's day and week units for snapshotting.interval

Originally, I had a patch that would replace all usages of
time.Duration in package config with the new config.Duration
types, but:
1. these are all timeouts/retry intervals that have default values.
   Most users don't touch them, and if they do, they don't need
   day or week units.
2. go-yaml's error reporting for yaml.Unmarshaler is inferior to
   built-in types (line numbers are missing, so the error would not have
   sufficient context)

fixes https://github.com/zrepl/zrepl/issues/486
This commit is contained in:
Christian Schwarz
2022-10-09 15:27:17 +02:00
parent 1da8f848f2
commit 3ffb69bfb0
4 changed files with 131 additions and 53 deletions
+2 -2
View File
@@ -22,7 +22,7 @@ func periodicFromConfig(g *config.Global, fsf zfs.DatasetFilter, in *config.Snap
if in.Prefix == "" {
return nil, errors.New("prefix must not be empty")
}
if in.Interval <= 0 {
if in.Interval.Duration() <= 0 {
return nil, errors.New("interval must be positive")
}
@@ -32,7 +32,7 @@ func periodicFromConfig(g *config.Global, fsf zfs.DatasetFilter, in *config.Snap
}
args := periodicArgs{
interval: in.Interval,
interval: in.Interval.Duration(),
fsf: fsf,
planArgs: planArgs{
prefix: in.Prefix,