ifms_go/test/corn_test.go
2025-06-10 17:50:46 +08:00

36 lines
671 B
Go

package test
import (
"fmt"
"github.com/robfig/cron/v3"
"log"
"testing"
"time"
)
func TestCorn(t *testing.T) {
c := cron.New(cron.WithSeconds())
// 定义一个定时任务,每分钟执行一次
_, err := c.AddFunc("0/10 * * * * *", func() {
fmt.Println("Cron job executed:", time.Now())
})
//if err != nil {
// log.Fatal(err)
//}
//
//// 定义另一个定时任务,每小时执行一次
//_, err = c.AddFunc("0 0 * * * *", func() {
// fmt.Println("Hourly cron job executed:", time.Now())
//})
if err != nil {
log.Fatal(err)
}
// 启动定时任务调度器
c.Start()
// 让主 goroutine 持续运行,直到程序退出
select {}
}