Reload job in ui
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"local/firestormy/config"
|
||||
"local/firestormy/config/ns"
|
||||
"log"
|
||||
"local/firestormy/scheduler"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -52,12 +52,31 @@ func (u *upsertRequest) validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *upsertRequest) toJob() (*scheduler.Job, error) {
|
||||
j, err := scheduler.NewJob(scheduler.Bash, u.Cron, u.Script)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
j.Title = u.Title
|
||||
j.Name = u.ID
|
||||
j.Disabled = u.Disabled
|
||||
return j, err
|
||||
}
|
||||
|
||||
func (s *Server) upsert(w http.ResponseWriter, r *http.Request) {
|
||||
upsert, err := newUpsertRequest(r.Body)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
log.Println("received", upsert)
|
||||
http.Error(w, "not impl", http.StatusNotImplemented)
|
||||
job, err := upsert.toJob()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if err := scheduler.Schedule.Update(job); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user