ecodeclub / ecron

大规模分布式任务调度系统(学习版)
Apache License 2.0
78 stars 21 forks source link

http客户端 #32

Closed Jared-lu closed 2 weeks ago

Jared-lu commented 1 month ago

28 http客户端

Registry 里面我使用map存储用户注册的任务

type Registry struct {
    tasks map[string]EcronTask
}

客户端监听用户指定的 prefix,然后根据任务名去执行相应的Task

http.HandleFunc("$prefix", func(w http.ResponseWriter, r *http.Request) {
    name, _ := strings.CutPrefix(r.RequestURI, c.prefix)
    //POST => c.tasks[name].Task.Execute()
    //GET => c.tasks[name].Task.Status()
    //DELETE = >c.tasks[name].Task.Stop()
})

用户在注册任务时要保证任务名称不重复,否则会在注册时panic