稳定版本

This commit is contained in:
Yun
2023-11-27 22:37:33 +08:00
parent fbb74cdd6d
commit 362d1f455a
12 changed files with 28 additions and 246 deletions
+15 -56
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"time"
"code.yun.ink/open/timer"
"code.yun.ink/pkg/timerx"
"github.com/go-redis/redis/v8"
)
@@ -30,7 +30,7 @@ func main() {
func worker() {
client := getRedis()
w := timer.InitWorker(context.Background(), client, &Worker{})
w := timerx.InitOnce(context.Background(), client, &Worker{})
w.Add("test", "test", 1*time.Second, map[string]interface{}{
"test": "test",
})
@@ -52,11 +52,11 @@ func worker() {
type Worker struct{}
func (w *Worker) Worker(uniqueKey string, jobType string,data map[string]interface{}) timer.WorkerCode {
func (w *Worker) Worker(uniqueKey string, jobType string, data interface{}) (timerx.WorkerCode, time.Duration) {
fmt.Println("执行时间:", time.Now().Format("2006-01-02 15:04:05"))
fmt.Println(uniqueKey, jobType)
fmt.Println(data)
return timer.WorkerCodeAgain
return timerx.WorkerCodeAgain,time.Second
}
func getRedis() *redis.Client {
@@ -76,63 +76,22 @@ func re() {
client := getRedis()
ctx := context.Background()
cl := timer.InitCluster(ctx, client)
cl.AddTimer(ctx, "test1", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text1",
},
})
cl.AddTimer(ctx, "test2", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text2",
},
})
cl.AddTimer(ctx, "test3", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text3",
},
})
cl.AddTimer(ctx, "test4", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text4",
},
})
cl.AddTimer(ctx, "test5", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text5",
},
})
cl.AddTimer(ctx, "test6", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text6",
},
})
cl.AddTimer(ctx, "test7", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text7",
},
})
cl.AddTimer(ctx, "test8", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text8",
},
})
cl.AddTimer(ctx, "test9", 1*time.Millisecond, aa, timer.ExtendParams{
Params: map[string]interface{}{
"test": "text9",
},
})
cl := timerx.InitCluster(ctx, client)
cl.Add(ctx, "test1", 1*time.Millisecond, aa, "data")
cl.Add(ctx, "test2", 1*time.Millisecond, aa, "data")
cl.Add(ctx, "test3", 1*time.Millisecond, aa, "data")
cl.Add(ctx, "test4", 1*time.Millisecond, aa, "data")
cl.Add(ctx, "test5", 1*time.Millisecond, aa, "data")
cl.Add(ctx, "test6", 1*time.Millisecond, aa, "data")
select {}
}
func aa(ctx context.Context) bool {
// fmt.Println(time.Now().Format(time.RFC3339))
// fmt.Println("gggggggggggggggggggggggggggg")
a, err := timer.GetExtendParams(ctx)
fmt.Printf("%+v %+v \n\n", a, err)
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)
return true
return nil
}
func d() {