crontab 时间通过
This commit is contained in:
parent
f82f388867
commit
a4b4afdffd
@ -72,7 +72,7 @@ func (cron *Crontab) FromString(crontab string) error {
|
||||
|
||||
// CreateYearPlan 创建年度计划
|
||||
func (cron *Crontab) CreateYearPlan() {
|
||||
cron.YearPlan = newTrieYear(time.Now().Year())
|
||||
cron.YearPlan = newTrieYear()
|
||||
cron.YearPlan.FromCrontab(cron)
|
||||
}
|
||||
|
||||
@ -105,13 +105,13 @@ func (cron *Crontab) TimeUp(now time.Time) bool {
|
||||
istimeup = true
|
||||
} else {
|
||||
if istimeup {
|
||||
if i > 0 {
|
||||
cron.SkipPlans = append(cron.SkipPlans, cron.WillPlans[0:i]...)
|
||||
if i-1 > 0 {
|
||||
cron.SkipPlans = append(cron.SkipPlans, cron.WillPlans[0:i-1]...)
|
||||
if len(cron.SkipPlans) >= maxlen+200 {
|
||||
cron.SkipPlans = cron.SkipPlans[200:]
|
||||
}
|
||||
}
|
||||
cron.WillPlans = cron.WillPlans[i+1:]
|
||||
cron.WillPlans = cron.WillPlans[i:]
|
||||
return istimeup
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package curl2info
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
@ -15,53 +14,21 @@ import (
|
||||
func TestParseCrontab(t *testing.T) {
|
||||
// crontab := "0-5/2,7-30/3,30,35,40-^1 * * * *" //(秒) 分 时 号(每月的多少号, 要注意月可可能性) 星期几(每个星期的) /每 ,列表 -范围
|
||||
crontab := "* * * * *"
|
||||
t.Error("")
|
||||
// t.Error(NewCrontab(crontab))
|
||||
|
||||
var s []*TrieYear
|
||||
PrintMemUsage()
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
ty := newTrieYear(2018)
|
||||
ty.FromCrontab(NewCrontab(crontab))
|
||||
s = append(s, ty)
|
||||
}
|
||||
|
||||
ty := newTrieYear(2018)
|
||||
ty := newTrieYear()
|
||||
cron := NewCrontab(crontab)
|
||||
ty.FromCrontab(cron)
|
||||
|
||||
t1 := time.Now()
|
||||
log.Println(ty.GetPlanTime(cron, time.Now(), 10))
|
||||
log.Println(time.Since(t1))
|
||||
if len(ty.GetPlanTime(cron, time.Now(), 10)) != 10 {
|
||||
t.Error("GetPlanTime error len != 10")
|
||||
}
|
||||
|
||||
cron.CreateYearPlan()
|
||||
|
||||
cur := time.Now().Add(time.Minute * 2)
|
||||
for i := 0; i < 510; i++ {
|
||||
|
||||
if i >= 499 {
|
||||
// log.Println("skip:", cron.SkipPlans, len(cron.SkipPlans))
|
||||
log.Println(cur, "will:", cron.WillPlans[0:10], len(cron.WillPlans))
|
||||
log.Println("skip:", cron.SkipPlans)
|
||||
if !cron.TimeUp(time.Now()) {
|
||||
t.Error("timeup error")
|
||||
}
|
||||
log.Println(cron.TimeUp(cur))
|
||||
cur = cur.Add(time.Minute * 1) // 模拟出来的分绝对一分钟, 程序损耗会多几毫秒
|
||||
// time.Sleep(time.Minute * 1)
|
||||
}
|
||||
|
||||
// for {
|
||||
|
||||
// i := ty.TimeUp()
|
||||
// if i != nil {
|
||||
// if i.GetStatus() {
|
||||
// spew.Dump(i)
|
||||
// log.Println(time.Now())
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// time.Sleep(time.Millisecond * 200)
|
||||
// }
|
||||
|
||||
PrintMemUsage()
|
||||
|
||||
|
@ -98,7 +98,7 @@ func (ty *TrieYear) clearHour() {
|
||||
|
||||
}
|
||||
|
||||
func newTrieYear(year int) *TrieYear {
|
||||
func newTrieYear() *TrieYear {
|
||||
ty := TrieYear{}
|
||||
ty.Year = time.Now().Year()
|
||||
return &ty
|
||||
|
Loading…
x
Reference in New Issue
Block a user