Move jobs raw definition to their own namespace and the cascading fallout
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"local/firestormy/config"
|
||||
"local/firestormy/config/ns"
|
||||
"local/firestormy/scheduler"
|
||||
"time"
|
||||
)
|
||||
@@ -16,7 +18,8 @@ func toMap(j *scheduler.Job) map[string]interface{} {
|
||||
out["title"] = j.Title
|
||||
out["cron"] = j.Schedule
|
||||
out["language"] = j.Runner.String()
|
||||
out["script"] = j.Raw
|
||||
b, _ := config.Store.Get(j.Name, ns.JobsRaw...)
|
||||
out["script"] = string(b)
|
||||
out["last"] = map[string]interface{}{
|
||||
"run": j.LastRun.In(tz).Format(`2006-01-02 15:04:05 MST`),
|
||||
"runtime": j.LastRuntime.String(),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user