inital code for snapshoting on cron
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package configuration
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/go-co-op/gocron"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type Schedule struct {
|
||||
Every int
|
||||
Unit string
|
||||
At []string
|
||||
}
|
||||
|
||||
|
||||
|
||||
func (s Schedule) ToGocron() *gocron.Scheduler {
|
||||
out := gocron.NewScheduler(time.Local)
|
||||
out = out.Every(s.Every)
|
||||
|
||||
switch s.Unit {
|
||||
case "Day":
|
||||
out = out.Day()
|
||||
case "Hour":
|
||||
out = out.Hour()
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, at := range s.At {
|
||||
out = out.At(at)
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
type SnapJob struct {
|
||||
Name string `yaml:"name"`
|
||||
DatasetPath string `yaml:"dataset_path"`
|
||||
Description string `yaml:"descriptions"`
|
||||
Recursive bool `yaml:"recursive"`
|
||||
Schedules []Schedule `yaml:"schedules"`
|
||||
Cron string `yaml:"cron"`
|
||||
}
|
||||
|
||||
func LoadSnap(path string) (*SnapJob, error) {
|
||||
configFile, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var jobInfo SnapJob
|
||||
err = yaml.Unmarshal(configFile, &jobInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &jobInfo, nil
|
||||
}
|
||||
Reference in New Issue
Block a user