update sanity check when parsing config

This commit is contained in:
shoopea
2023-06-29 23:20:46 +02:00
parent 7e8a34a435
commit 3c785dec8b
3 changed files with 20 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"regexp"
"sync"
"time"
@@ -132,6 +133,20 @@ func (c *Config) LoadFile(path string) error {
return err
}
c.apps[v.Name] = a
for k, _ := range a.schedule {
if dur, ok := c.ScheduleDuration[k]; ok {
re := regexp.MustCompile(`^forever|([0-9]+(h|d|m|y))+$`)
if !re.MatchString(dur) {
err := errors.New("incorrect schedule duration")
log.WithFields(log.Fields{"path": path, "app": v.Name, "schedule": k, "error": err}).Errorf("")
return err
}
} else {
err := errors.New("undefined schedule duration")
log.WithFields(log.Fields{"path": path, "app": v.Name, "schedule": k, "error": err}).Errorf("")
return err
}
}
}
}