diff --git a/keeper.go b/keeper.go index ea58d10..a806acd 100644 --- a/keeper.go +++ b/keeper.go @@ -230,6 +230,16 @@ func (k *Keeper) DelTask(name string) error { return k.save() } +func (k *Keeper) RunTask(name string) error { + fmt.Println("==========runtask==========") + + if tk, ok := k.tasks[name]; ok { + tk.Run(TRIGGER_MANUAL) + return nil + } + return errors.New("Can't run tasks") +} + func (k *Keeper) PutTask(name string, t Task) error { k.tkmu.Lock() defer k.tkmu.Unlock() diff --git a/templates/homepage.html b/templates/homepage.html index 8006c33..c672a0b 100644 --- a/templates/homepage.html +++ b/templates/homepage.html @@ -15,6 +15,18 @@ } var top = 400; var duration = 2000; + $scope.runTask = function(taskName){ + console.log(taskName); + $http.post("/run/",{'name':taskName}) + .success(function(res){ + console.log("return"); + }) + .error(function(res){ + console.log("err"); + }); + window.location="/"+taskName + return false; + }; }); @@ -47,6 +59,7 @@

+ #{{t.index}} diff --git a/web.go b/web.go index 58e416d..b682933 100644 --- a/web.go +++ b/web.go @@ -95,6 +95,25 @@ func initRoutes() { ctx.HTML(200, "settings") }) + m.Post("/run/", func(ctx *macaron.Context) { + type T struct { + Name string + } + var t T + dec := json.NewDecoder(ctx.Req.Body().ReadCloser()) + if err := dec.Decode(&t); err != nil { + ctx.Error(500, err.Error()) + return + } + log.Println(t.Name) + if err := keeper.RunTask(t.Name); err != nil { + ctx.Error(500, err.Error()) + return + } + + ctx.JSON(200, "success") + }) + m.Get("/api/records/:name/index/:index", func(ctx *macaron.Context) { name := ctx.Params(":name") index := ctx.ParamsInt(":index")