small changes and force run for release

This commit is contained in:
bel
2020-03-16 04:50:09 +00:00
parent 9ec88a5ce8
commit 13edf77b08
6 changed files with 86 additions and 4 deletions

View File

@@ -36,6 +36,10 @@ func (s *Server) Routes() error {
path: fmt.Sprintf("/api/job/enable/%s", router.Wildcard),
handler: s.gzip(s.authenticate(s.enable)),
},
{
path: fmt.Sprintf("/api/job/run/%s", router.Wildcard),
handler: s.gzip(s.authenticate(s.run)),
},
{
path: fmt.Sprintf("%s%s", wildcard, wildcard),
handler: s.gzip(s.authenticate(s.static)),

42
server/run.go Normal file
View File

@@ -0,0 +1,42 @@
package server
import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/scheduler"
"net/http"
"strings"
)
func (s *Server) run(w http.ResponseWriter, r *http.Request) {
keys := strings.Split(r.URL.Path, "/")
key := keys[len(keys)-1]
j := &scheduler.Job{}
b, err := config.Store.Get(key, ns.Jobs...)
if err != nil {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
if err := j.Decode(b); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
func() {
defer func() {
if e := recover(); e != nil {
if er, ok := e.(error); ok {
err = er
}
}
}()
j.Run()
}()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write([]byte("{}"))
}