mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2025-12-13 07:44:59 +00:00
cron
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user