This commit is contained in:
huangsimin 2018-12-07 03:02:19 +08:00
parent 8c70be8fd0
commit f3702f9df0

View File

@ -67,6 +67,21 @@ func NewCrontab(crontab string) *Crontab {
return cron
}
// UnmarshalYAML 添加序列化接口 Marshal没实现, 需要的时候可以自己添加
func (cron *Crontab) UnmarshalYAML(unmarshal func(interface{}) error) error {
var buf string
err := unmarshal(&buf)
if err != nil {
return nil
}
if err := cron.FromString(buf); err != nil {
return err
}
return nil
}
// SetStatus 设置状态 接口定义
func (cron *Crontab) SetStatus(status interface{}) {
@ -119,13 +134,13 @@ func (cron *Crontab) FromString(crontab string) error {
switch mlen {
case 1:
// "f1-2|5-10x5,f1|10m,10-15,f1"
cron.nextTime = time.Now()
cron.lastStatus = true
cron.interval = clinked.NewCircularLinked()
var intervalList []interface{}
intervalList = parseIntervalString(matches[0])
cron.interval.Append(intervalList...)
cron.TimeUp()
case 5:
cron.min = createTimePointer(matches[0], 0, 59, true)
cron.hour = createTimePointer(matches[1], 0, 23, true)
@ -134,6 +149,7 @@ func (cron *Crontab) FromString(crontab string) error {
cron.week = createTimePointer(matches[4], 0, 6, true)
cron.createYearPlan()
cron.TimeUp()
default:
return errors.New("mathches len != want, check crontab string")
}