优化&测试

This commit is contained in:
Yun
2024-05-22 15:02:39 +08:00
parent 7912bbc56c
commit 4d769cf997
7 changed files with 107 additions and 43 deletions
+19 -3
View File
@@ -5,8 +5,8 @@ import (
"fmt"
"time"
"github.com/yuninks/timerx"
"github.com/go-redis/redis/v8"
"github.com/yuninks/timerx"
)
func main() {
@@ -24,8 +24,24 @@ func main() {
// re()
// d()
worker()
cluster()
select {}
}
func cluster() {
client := getRedis()
ctx := context.Background()
cluster := timerx.InitCluster(ctx, client, "test")
err := cluster.AddSpace(ctx, "test_space", 1*time.Second, aa, "这是秒任务")
fmt.Println(err)
err = cluster.AddMinute(ctx, "test_min", 15, aa, "这是分钟任务")
fmt.Println(err)
err = cluster.AddHour(ctx, "test_hour", 30, 0, aa, "这是小时任务")
fmt.Println(err)
err = cluster.AddDay(ctx, "test_day", 11, 0, 0, aa, "这是天任务")
fmt.Println(err)
}
func worker() {
@@ -90,7 +106,7 @@ func re() {
func aa(ctx context.Context, data interface{}) error {
fmt.Println("执行时间:", time.Now().Format("2006-01-02 15:04:05"))
fmt.Println(data)
time.Sleep(time.Second * 5)
// time.Sleep(time.Second * 5)
return nil
}