添加注释, 和日志打印
This commit is contained in:
parent
b7f0209cc3
commit
40683dc466
12
crontab.go
12
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++
|
||||
|
|
|
@ -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) {
|
||||
|
|
10
trie_year.go
10
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)
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user