// Package task ... // // Description : task ... // // Author : go_developer@163.com<白茶清欢> // // Date : 2023-08-11 17:00 package task import ( "context" "fmt" "git.zhangdeman.cn/zhangdeman/wrapper" "testing" "time" ) var tw *TimeWheel // TestNewTimeWheel ... // // Author : go_developer@163.com<白茶清欢> // // Date : 17:00 2023/8/11 func TestNewTimeWheel(t *testing.T) { tw = NewTimeWheel(10, 10*time.Second) tw.AddTask(&Task{ Key: wrapper.StringFromRandom(32, "").Value(), Interval: 5 * time.Second, CreatedTime: time.Now(), Position: 0, Circle: 100, Job: &testTask{}, Times: 10, MaxExecuteTime: 0, }, false) go tw.Start() time.Sleep(3 * time.Second) for tw.IsRunning { } } type testTask struct { } func (t testTask) GetFlag() string { return "unit_test" } func (t testTask) Description() string { return "单元测试任务" } func (t testTask) GetRunID() string { return wrapper.StringFromRandom(32, "").Value() } func (t testTask) Callback(result *Result) error { fmt.Println(result) return nil } func (t testTask) Execute(ctx context.Context, cfg *Config) (map[string]interface{}, error) { fmt.Println(wrapper.OwnTimeFromNow().ToString()) return nil, nil }