正在重新封装goCron...

This commit is contained in:
free will committed 2022-05-18 17:33:14 +08:00
1 parent 0da380c22f
commit aa86d20191
1 file changed
+28 -5
+28 -5
View File
@@ -16,7 +16,7 @@ import (
)
func printHHH() {
println("hello,gocron.",time.Now().String())
println("hello,gocron.", time.Now().String())
}
//
@@ -31,7 +31,7 @@ func Test_Loop(t *testing.T) {
s := gocron.NewScheduler(time.UTC)
// Job:只知道它提供的任务(task, go函数),因此只能执行与该任务相关的操作,例如防止自己超出需要很长时间的先前任务。
//j, _ := s.Every(10).Seconds().Do(func() { time.Sleep(2 * time.Second); printHHH()})
j, _ := s.Every(1).Seconds().Do(func() { printHHH()})
j, _ := s.Every(1).Seconds().Do(func() { printHHH() })
// Executor:顾名思义,executor 只负责调用Scheduler(调度程序)发送时,Job(作业)交给它的任务(go 函数)。
fmt.Println(j.IsRunning())
@@ -50,7 +50,7 @@ func Test_Loop(t *testing.T) {
func Test_IsRunning(t *testing.T) {
s := gocron.NewScheduler(time.UTC)
// Job:只知道它提供的任务(task, go函数),因此只能执行与该任务相关的操作,例如防止自己超出需要很长时间的先前任务。
j, _ := s.Every(10).Seconds().Do(func() { time.Sleep(2 * time.Second); printHHH()})
j, _ := s.Every(10).Seconds().Do(func() { time.Sleep(2 * time.Second); printHHH() })
// Executor:顾名思义,executor 只负责调用Scheduler(调度程序)发送时,Job(作业)交给它的任务(go 函数)。
fmt.Println(j.IsRunning())
@@ -71,6 +71,29 @@ func Test_IsRunning(t *testing.T) {
var task = func() {}
func Test_Run1Time(t *testing.T) {
// 触发时间设置到五秒后
timeRun := time.Now()
//dur := 5 * time.Second
//timeRun.Add(dur)
// 设置触发事件
s := gocron.NewScheduler(time.UTC)
_, _ = s.At(timeRun).Do(printHHH)
//go func() {
// for {
// fmt.Println("Run count", job.RunCount())
// time.Sleep(time.Second)
// }
//}()
s.StartAsync()
// 保活
for true {
time.Sleep(10 * time.Second)
}
}
//
// Test_RunCount
// @Description: 测试job.RunCount()
@@ -141,7 +164,7 @@ func Test_LimitRunsTo(t *testing.T) {
func Test_ScheduleAtTimes(t *testing.T) {
// 设置一个触发时间
s := gocron.NewScheduler(time.UTC)
job, _ := s.Every(1).Day().At("20:02").Do(func() {printHHH()})
job, _ := s.Every(1).Day().At("20:02").Do(func() { printHHH() })
s.StartAsync()
fmt.Println(job.ScheduledAtTime())
@@ -179,4 +202,4 @@ func Test_SingletonMode(t *testing.T) {
time.Sleep(3 * time.Second)
fmt.Println("Last run:", job.LastRun())
}
}
}