diff --git a/crontab.go b/crontab.go index a11682b..7d7a424 100644 --- a/crontab.go +++ b/crontab.go @@ -219,7 +219,7 @@ func (cron *Crontab) linuxTimeUp() bool { createlen := 500 plen := len(cron.WillPlans) - if plen <= createlen { + if plen <= createlen { // 如果当前生成的计划表少于 限制的500. 就生成新的计划表 var lastplan time.Time if plen == 0 { lastplan = now @@ -237,9 +237,13 @@ func (cron *Crontab) linuxTimeUp() bool { if len(cron.WillPlans) > 0 { istimeup := false for i := 0; i < maxlen; i++ { + + // 统计过了多少计划任务时间表 i - 1 if now.Unix() >= cron.WillPlans[i].Unix() { istimeup = true } else { + + // 清除过时的计划任务时间表 if istimeup { if i-1 > 0 { cron.SkipPlans = append(cron.SkipPlans, cron.WillPlans[0:i-1]...) @@ -254,7 +258,7 @@ func (cron *Crontab) linuxTimeUp() bool { return istimeup } } - + // 如果所有计划表都不符合, 全部放到忽略的计划表上, 这个表方便打印查看, 因为程序执行超时过了多少计划任务 cron.SkipPlans = append(cron.SkipPlans, cron.WillPlans...) cron.WillPlans = nil return istimeup @@ -289,10 +293,10 @@ func (cron *Crontab) intervalCalculateNextTime(now time.Time) { isecond = 0 } - } else { - log.Println("success:", cron.trueCount, "count time wait:", isecond, "s") } + log.Println("success:", cron.trueCount, "count time wait:", isecond, "s") + } else { cron.failCount++ diff --git a/crontab_test.go b/crontab_test.go index fcb7225..7effffd 100644 --- a/crontab_test.go +++ b/crontab_test.go @@ -6,6 +6,8 @@ import ( "runtime" "testing" "time" + + "github.com/satori/go.uuid" ) // type LRValue struct { @@ -67,7 +69,11 @@ func isInRangeTime(sec, t float64) error { } func TestParseIntervalOnline1(t *testing.T) { + uid, _ := uuid.NewV4() + log.Println(string(uid.Bytes())) + crontab := "f[c > 2]=3|s[c <= 2]" + log.Println(crontab) } func TestParseIntervalPlus(t *testing.T) { diff --git a/trie_year.go b/trie_year.go index 55f65c5..f7b0094 100644 --- a/trie_year.go +++ b/trie_year.go @@ -123,7 +123,7 @@ func (ty *trieYear) GetPlanTime(cron *Crontab, aftertime time.Time, count uint) for j := 1; j <= 31; j++ { if nmonth == i { - if j < nday { + if j < nday { // 获取当天的计划表 continue } } @@ -132,7 +132,7 @@ func (ty *trieYear) GetPlanTime(cron *Crontab, aftertime time.Time, count uint) if day != nil { if day.IsClear { - insertHour(cron, day) + insertHour(cron, day) // 生成小时的计划表 } for k := 0; k <= 23; k++ { @@ -144,7 +144,7 @@ func (ty *trieYear) GetPlanTime(cron *Crontab, aftertime time.Time, count uint) } hour := day.Hour[k] - + // 遍历24小时 生成需要的计划表 if hour != nil { for n := 0; n <= 59; n++ { @@ -159,7 +159,7 @@ func (ty *trieYear) GetPlanTime(cron *Crontab, aftertime time.Time, count uint) curTime := time.Date(ty.Year, time.Month(i), j, k, n, 0, 0, time.Local) result = append(result, curTime) - count-- + count-- // 统计完当前需要的计划任务后就结束 if count <= 0 { ty.clearHour() return result @@ -168,8 +168,8 @@ func (ty *trieYear) GetPlanTime(cron *Crontab, aftertime time.Time, count uint) } } - } + } } } }