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) { btns.forEach(function(e) {
buttons += ` buttons += `
<span> <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> </span>
` `
}) })
@ -192,7 +192,8 @@ function getJobElement(id) {
function jobFromInput(input) { function jobFromInput(input) {
var b64 = input.getAttribute("job") var b64 = input.getAttribute("job")
var json = atob(b64) var encoded = atob(b64)
var json = decodeURIComponent(encoded)
return JSON.parse(json) return JSON.parse(json)
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,6 +8,7 @@ import (
"local/firestormy/config" "local/firestormy/config"
"local/firestormy/config/ns" "local/firestormy/config/ns"
"local/firestormy/scheduler" "local/firestormy/scheduler"
"local/logb"
"net/http" "net/http"
"github.com/google/uuid" "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) { func (s *Server) upsert(w http.ResponseWriter, r *http.Request) {
logb.Debugf("[access] upsert %s", r.URL.Path)
upsert, err := newUpsertRequest(r.Body) upsert, err := newUpsertRequest(r.Body)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) http.Error(w, err.Error(), http.StatusBadRequest)