fix 定时任务参数错误的问题

This commit is contained in:
陈景阳
2019-10-16 15:27:12 +08:00
parent ecab6dfa03
commit 05136b0fac
4 changed files with 61 additions and 23 deletions

View File

@@ -5,7 +5,7 @@ import (
"crawlab/lib/cron"
"crawlab/model"
"github.com/apex/log"
uuid "github.com/satori/go.uuid"
"github.com/satori/go.uuid"
"runtime/debug"
)
@@ -31,6 +31,9 @@ func AddTask(s model.Schedule) func() {
return
}
// 同步ID到定时任务
s.SyncNodeIdAndSpiderId(node, *spider)
// 生成任务ID
id := uuid.NewV4()
@@ -119,6 +122,18 @@ func (s *Scheduler) RemoveAll() {
}
}
// 验证cron表达式是否正确
func ParserCron(spec string) error {
parser := cron.NewParser(
cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
)
if _, err := parser.Parse(spec); err != nil {
return err
}
return nil
}
func (s *Scheduler) Update() error {
// 删除所有定时任务
s.RemoveAll()