This commit is contained in:
2021-04-11 15:02:27 +02:00
parent 5d92b5bcc1
commit 8a1fe41825
6 changed files with 91 additions and 3 deletions

View File

@@ -5,6 +5,10 @@ import (
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/cupcakearmy/autorestic/internal/lock"
"github.com/robfig/cron"
)
type HookArray = []string
@@ -163,3 +167,26 @@ func (l Location) Restore(to, from string, force bool) error {
}
return nil
}
func (l Location) RunCron() error {
if l.Cron == "" {
return nil
}
schedule, err := cron.ParseStandard(l.Cron)
if err != nil {
return err
}
last := lock.GetCron("test")
fmt.Println(last)
next := schedule.Next(time.Unix(last, 0))
fmt.Println(next)
now := time.Now()
if now.After(next) {
fmt.Println("Running")
lock.SetCron("test", now.Unix())
} else {
fmt.Println("Not due yet")
}
return nil
}