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