This commit is contained in:
bel
2020-03-16 00:48:06 +00:00
parent 8138e31e53
commit bdfdb41bba
6 changed files with 14 additions and 8 deletions

View File

@@ -2,7 +2,6 @@ package server
import (
"local/firestormy/scheduler"
"strings"
"time"
)
@@ -21,7 +20,7 @@ func toMap(j *scheduler.Job) map[string]interface{} {
out["last"] = map[string]interface{}{
"run": j.LastRun.In(tz).Format(`2006-01-02 15:04:05 MST`),
"runtime": j.LastRuntime.String(),
"output": strings.ReplaceAll(j.LastOutput, "\n", "<br>"),
"output": j.LastOutput,
"status": j.LastStatus,
}
return out

View File

@@ -33,7 +33,6 @@ func newUpsertRequest(r io.Reader) (upsertRequest, error) {
func (u *upsertRequest) validate() error {
if u.ID == "" {
u.ID = uuid.New().String()
} else if _, err := config.Store.Get(u.ID, ns.Jobs...); err != nil {
return fmt.Errorf("ID provided but not accessible: %v", err)
}
@@ -74,7 +73,16 @@ func (s *Server) upsert(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := scheduler.Schedule.Update(job); err != nil {
if job.Name == "" {
job.Name = uuid.New().String()
if job.Title == "" {
job.Title = job.Name
}
if err := scheduler.Schedule.Add(job); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
} else if err := scheduler.Schedule.Update(job); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}