1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| package main
import ( "fmt" "github.com/coreos/etcd/clientv3" go_task "github.com/pyihe/go-task" "time" )
func main() { config := clientv3.Config{ Endpoints: []string{"127.0.0.1:2379"}, DialTimeout: 5 * time.Second, } c, err := clientv3.New(config) if err != nil { fmt.Printf("new err: %v\n", err) return } defer c.Close()
tsker := go_task.NewTasker(c, "task", 10)
if err = tsker.RegisterHandler("key1", handler); err != nil { }
if err = tsker.Add("key1", "value1", "@every 1m", go_task.TaskTypeOnceCall); err != nil { }
if err = tsker.UpdateTime("key1", "value1", "@every 10m"); err != nil { }
if err = tsker.Remove("key1", "value1"); err != nil { } }
func handler(key, value string) { }
|