wip: ready for initial test

This commit is contained in:
2023-12-07 04:47:00 +00:00
parent ca6c2de4dc
commit 439baa60fb
4 changed files with 97 additions and 14 deletions

View File

@@ -18,8 +18,8 @@ const (
)
type Config struct {
servicePaths []string
cron []*cron
ServicePaths []string
Cron []*Cron
}
func Read() (*Config, error) {
@@ -33,14 +33,14 @@ func Read() (*Config, error) {
svcdir string
serviceAvailable bool
cronAvailable bool
cron []*cron
cron []*Cron
crontabfile string
)
serviceAvailable = false
cronAvailable = false
outConfig := &Config{
servicePaths: make([]string, 0),
ServicePaths: make([]string, 0),
}
configPath := viper.GetString(EnvConfigPath)
svcdir = filepath.Join(configPath, ServiceDirName)
@@ -49,7 +49,7 @@ func Read() (*Config, error) {
for _, d := range dirent {
if d.Type().IsRegular() {
serviceAvailable = true
outConfig.servicePaths = append(outConfig.servicePaths, filepath.Join(svcdir, d.Name()))
outConfig.ServicePaths = append(outConfig.ServicePaths, filepath.Join(svcdir, d.Name()))
}
}
}
@@ -60,7 +60,7 @@ func Read() (*Config, error) {
crontabfile = filepath.Join(configPath, CrontabFileName)
cron, err = readCrontab(crontabfile)
if len(cron) > 0 {
outConfig.cron = cron
outConfig.Cron = cron
cronAvailable = true
}
if err != nil {

View File

@@ -36,7 +36,7 @@ type CronTimeSpec interface {
// DayOfWeek() CronTimeSpec
// }
type cron struct {
type Cron struct {
minute CronTimeSpec
hour CronTimeSpec
dom CronTimeSpec
@@ -60,7 +60,7 @@ const (
dow
)
func readCrontab(path string) ([]*cron, error) {
func readCrontab(path string) ([]*Cron, error) {
var (
file *os.File
err error
@@ -68,7 +68,7 @@ func readCrontab(path string) ([]*cron, error) {
line string
re *regexp.Regexp
parts []string
retval []*cron
retval []*Cron
)
if re, err = regexp.Compile(CrontabEntryRegex); err != nil {
@@ -82,7 +82,7 @@ func readCrontab(path string) ([]*cron, error) {
_ = file.Close()
}()
retval = make([]*cron, 0)
retval = make([]*Cron, 0)
scanner = bufio.NewScanner(file)
for scanner.Scan() {
line = scanner.Text()
@@ -93,7 +93,7 @@ func readCrontab(path string) ([]*cron, error) {
continue
}
c := &cron{
c := &Cron{
hasRun: false,
}
if err = c.setField(minute, parts[1]); err != nil {
@@ -129,7 +129,11 @@ func readCrontab(path string) ([]*cron, error) {
return retval, nil
}
func (c *cron) TimeToRun(now time.Time) bool {
func (c *Cron) Command() string {
return c.command
}
func (c *Cron) TimeToRun(now time.Time) bool {
if !c.hasRun {
c.lastRun = now
c.hasRun = true
@@ -169,7 +173,7 @@ func (f *fieldRange) valid(u uint8) bool {
return i >= f.min && i <= f.max
}
func (c *cron) setField(field cronField, input string) error {
func (c *Cron) setField(field cronField, input string) error {
var (
fr *fieldRange
cField *CronTimeSpec