debug logs and b64 non encodable

master
bel 2020-04-08 02:25:24 +00:00
parent cc6b6f9226
commit 84400e4401
9 changed files with 25 additions and 2 deletions

View File

@ -64,7 +64,7 @@ function format(job) {
btns.forEach(function(e) {
buttons += `
<span>
<input type="button" onclick="job${e.name}(this);" value="&#${e.icon};" alt="${e.name}" title="${e.name}" job="${btoa(JSON.stringify(job))}"/>
<input type="button" onclick="job${e.name}(this);" value="&#${e.icon};" alt="${e.name}" title="${e.name}" job="${btoa(encodeURIComponent(JSON.stringify(job)))}"/>
</span>
`
})
@ -192,7 +192,8 @@ function getJobElement(id) {
function jobFromInput(input) {
var b64 = input.getAttribute("job")
var json = atob(b64)
var encoded = atob(b64)
var json = decodeURIComponent(encoded)
return JSON.parse(json)
}

View File

@ -7,6 +7,7 @@ import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/logger"
"local/logb"
"os/exec"
"strings"
"time"
@ -53,6 +54,7 @@ func newBashJob(schedule, sh string, title ...string) (*Job, error) {
j.Title = title[0]
}
j.foo = func() {
logb.Debugf("[sched] run %s/%s? %v", j.Title, j.Name, j.Disabled)
if j.Disabled {
return
}

View File

@ -8,6 +8,7 @@ import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/logger"
"local/logb"
"regexp"
"strings"
"time"
@ -111,6 +112,7 @@ func (s *Scheduler) Start() error {
}
s.cron.Start()
entries := s.cron.Entries()
logb.Debugf("[sched] start: %+v", entries)
logger.New().Info("started", len(entries), "jobs")
for _, entry := range entries {
logger.New().Info(fmt.Sprintf("%+v", entry))
@ -126,6 +128,7 @@ func (s *Scheduler) Stop() error {
func (s *Scheduler) List() ([]*Job, error) {
entries, err := config.Store.List(ns.Jobs)
logb.Debugf("[sched] list: %+v", entries)
if err != nil {
return nil, err
}
@ -157,6 +160,7 @@ func (s *Scheduler) loadJobFromStore(k string) (*Job, error) {
}
func (s *Scheduler) Update(j *Job) error {
logb.Debugf("[sched] update: %+v", j)
entryID, ok := s.getEntry(j)
if !ok {
return errors.New("job not found in storage")
@ -191,6 +195,7 @@ func (s *Scheduler) Update(j *Job) error {
}
func (s *Scheduler) Add(j *Job) error {
logb.Debugf("[sched] add: %+v", j)
if _, ok := s.getEntry(j); ok {
return ErrDuplicateJob
}
@ -210,6 +215,7 @@ func (s *Scheduler) Add(j *Job) error {
}
func (s *Scheduler) Remove(j *Job) error {
logb.Debugf("[sched] rm: %+v", j)
entryID, ok := s.getEntry(j)
if !ok {
return ErrJobNotFound

View File

@ -4,15 +4,18 @@ import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/scheduler"
"local/logb"
"net/http"
"strings"
)
func (s *Server) disable(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] disable %s", r.URL.Path)
s.setDisabled(w, r, true)
}
func (s *Server) enable(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] enable %s", r.URL.Path)
s.setDisabled(w, r, false)
}

View File

@ -4,11 +4,13 @@ import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/scheduler"
"local/logb"
"net/http"
"strings"
)
func (s *Server) delete(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] delete %s", r.URL.Path)
keys := strings.Split(r.URL.Path, "/")
key := keys[len(keys)-1]

View File

@ -5,11 +5,13 @@ import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/scheduler"
"local/logb"
"net/http"
"strings"
)
func (s *Server) get(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] get %s", r.URL.Path)
keys := strings.Split(r.URL.Path, "/")
key := keys[len(keys)-1]

View File

@ -5,12 +5,15 @@ import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/scheduler"
"local/logb"
"net/http"
"sort"
)
func (s *Server) list(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] list %s", r.URL.Path)
jobs, err := config.Store.List(ns.Jobs)
logb.Debugf("[access] list : %v: %+v", err, jobs)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return

View File

@ -4,11 +4,13 @@ import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/scheduler"
"local/logb"
"net/http"
"strings"
)
func (s *Server) run(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] run %s", r.URL.Path)
keys := strings.Split(r.URL.Path, "/")
key := keys[len(keys)-1]

View File

@ -8,6 +8,7 @@ import (
"local/firestormy/config"
"local/firestormy/config/ns"
"local/firestormy/scheduler"
"local/logb"
"net/http"
"github.com/google/uuid"
@ -63,6 +64,7 @@ func (u *upsertRequest) toJob() (*scheduler.Job, error) {
}
func (s *Server) upsert(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] upsert %s", r.URL.Path)
upsert, err := newUpsertRequest(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)