Move jobs raw definition to their own namespace and the cascading fallout

This commit is contained in:
Bel LaPointe
2020-04-24 09:52:34 -06:00
parent d9b10029ae
commit 9bd9c47895
7 changed files with 84 additions and 35 deletions

View File

@@ -10,8 +10,6 @@ import (
"local/firestormy/scheduler"
"local/logb"
"net/http"
"github.com/google/uuid"
)
type upsertRequest struct {
@@ -58,7 +56,9 @@ func (u *upsertRequest) toJob() (*scheduler.Job, error) {
return nil, err
}
j.Title = u.Title
j.Name = u.ID
if u.ID != "" {
err = j.Rename(u.ID)
}
j.Disabled = u.Disabled
return j, err
}
@@ -75,11 +75,7 @@ func (s *Server) upsert(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if job.Name == "" {
job.Name = uuid.New().String()
if job.Title == "" {
job.Title = job.Name
}
if upsert.ID == "" {
if err := scheduler.Schedule.Add(job); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return