From c35c07f8c3533a72bd1eeee3836a9c39edebc869 Mon Sep 17 00:00:00 2001 From: bel Date: Mon, 16 Mar 2020 04:50:09 +0000 Subject: [PATCH] small changes and force run for release --- .dockerignore | 2 ++ Dockerfile | 23 +++++++++++++++++++++++ TODO.md | 6 ++++-- public/js/js.js | 13 +++++++++++-- server/routes.go | 4 ++++ server/run.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100755 Dockerfile create mode 100644 server/run.go diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c0382aa --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +vendor +**/*.sw* diff --git a/Dockerfile b/Dockerfile new file mode 100755 index 0000000..d34b420 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ + +FROM frolvlad/alpine-glibc:alpine-3.11_glibc-2.30 +RUN apk update \ + && apk add --no-cache \ + ca-certificates \ + bash \ + jq \ + python3 \ + curl \ + && apk add --no-cache tzdata \ + && cp /usr/share/zoneinfo/America/Denver /etc/localtime \ + && echo "America/Denver" > /etc/timezone + +RUN mkdir -p /var/log +WORKDIR /main + +COPY . . + +ENV GOPATH="" +ENV MNT="/mnt/" +ENTRYPOINT ["/main/firestormy"] +CMD [] + diff --git a/TODO.md b/TODO.md index 12815f0..c30cd54 100755 --- a/TODO.md +++ b/TODO.md @@ -11,12 +11,14 @@ x job title includes last pass/fail icon x button to modify (copies to upsert form) x button to delete + 1. last run with title + 1. word wrap or truncate output 1. UI to mutate + 1. force run x submit job x delete job x pause jobs 1. interrupt job - 1. force run x JS x ajax for json calls @@ -25,6 +27,7 @@ x JS x load from file 1. interrupt running jobs 1. json API + 1. force run 1. list x last run output x last run pass/fail bool @@ -35,7 +38,6 @@ x load from file x disable job 1. running job 1. interrupt job - 1. force run 1. change cron to load the full job from storage so not holding big queued jobs in ram x add optional second for test main 1. test main diff --git a/public/js/js.js b/public/js/js.js index ceec689..46cd28c 100755 --- a/public/js/js.js +++ b/public/js/js.js @@ -57,8 +57,7 @@ function format(job) { var buttons = "" var btns = [ {"name":"refresh", "icon":"8635"}, - {"name":"disable", "icon":"11035"}, - {"name":"enable", "icon":"9654"}, + {"name":"run", "icon":"9654"}, {"name":"modify", "icon":"9999"}, {"name":"delete", "icon":"10006"} ] @@ -118,6 +117,16 @@ function jobenable(input) { getField("disabled").checked = false } +function jobrun(input) { + var job = jobFromInput(input) + function cb(body, status) { + if (status != 200) { + console.log("failed to run job: ", status, body) + } + } + http("GET", "/api/job/run/"+job.id, cb, null) +} + function jobmodify(input) { var form = getForm() var job = jobFromInput(input) diff --git a/server/routes.go b/server/routes.go index 187a7ff..b964800 100755 --- a/server/routes.go +++ b/server/routes.go @@ -36,6 +36,10 @@ func (s *Server) Routes() error { path: fmt.Sprintf("/api/job/enable/%s", router.Wildcard), handler: s.gzip(s.authenticate(s.enable)), }, + { + path: fmt.Sprintf("/api/job/run/%s", router.Wildcard), + handler: s.gzip(s.authenticate(s.run)), + }, { path: fmt.Sprintf("%s%s", wildcard, wildcard), handler: s.gzip(s.authenticate(s.static)), diff --git a/server/run.go b/server/run.go new file mode 100644 index 0000000..b8cf184 --- /dev/null +++ b/server/run.go @@ -0,0 +1,42 @@ +package server + +import ( + "local/firestormy/config" + "local/firestormy/config/ns" + "local/firestormy/scheduler" + "net/http" + "strings" +) + +func (s *Server) run(w http.ResponseWriter, r *http.Request) { + keys := strings.Split(r.URL.Path, "/") + key := keys[len(keys)-1] + + j := &scheduler.Job{} + b, err := config.Store.Get(key, ns.Jobs...) + if err != nil { + http.Error(w, err.Error(), http.StatusNotFound) + return + } + if err := j.Decode(b); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + func() { + defer func() { + if e := recover(); e != nil { + if er, ok := e.(error); ok { + err = er + } + } + }() + j.Run() + }() + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.Write([]byte("{}")) +}