implement enable disable with client side display and mod
parent
89822b7012
commit
a8e50d3ce4
5
TODO.md
5
TODO.md
|
|
@ -24,7 +24,6 @@ x JS
|
||||||
|
|
||||||
x load from file
|
x load from file
|
||||||
1. interrupt running jobs
|
1. interrupt running jobs
|
||||||
1. disable jobs
|
|
||||||
1. json API
|
1. json API
|
||||||
1. list
|
1. list
|
||||||
x last run output
|
x last run output
|
||||||
|
|
@ -32,8 +31,8 @@ x load from file
|
||||||
x last run timestamp
|
x last run timestamp
|
||||||
1. next run
|
1. next run
|
||||||
x upsert
|
x upsert
|
||||||
1. delete job
|
x delete job
|
||||||
1. pause/disable job
|
x disable job
|
||||||
1. running job
|
1. running job
|
||||||
1. interrupt job
|
1. interrupt job
|
||||||
1. force run
|
1. force run
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ function upsert() {
|
||||||
console.log("error upserting:", status, body)
|
console.log("error upserting:", status, body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log("to upsert", jsonifyForm("upsert"))
|
||||||
http("POST", "/api/job/upsert", cb, jsonifyForm("upsert"))
|
http("POST", "/api/job/upsert", cb, jsonifyForm("upsert"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,6 +28,7 @@ function jsonifyForm(id) {
|
||||||
var form = document.getElementById(id)
|
var form = document.getElementById(id)
|
||||||
var entries = new FormData(form).entries();
|
var entries = new FormData(form).entries();
|
||||||
var json = Object.assign(...Array.from(entries, ([x,y]) => ({[x]:y})));
|
var json = Object.assign(...Array.from(entries, ([x,y]) => ({[x]:y})));
|
||||||
|
json.disabled = json.disabled == "false"
|
||||||
var s = JSON.stringify(json)
|
var s = JSON.stringify(json)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
@ -67,15 +69,19 @@ function format(job) {
|
||||||
</span>
|
</span>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
|
var strikethrough = "initial"
|
||||||
|
if (job.disabled)
|
||||||
|
strikethrough = "line-through"
|
||||||
|
strikethrough = "text-decoration: "+strikethrough
|
||||||
return `<tr><td><details>
|
return `<tr><td><details>
|
||||||
<summary name="${job.id}">
|
<summary name="${job.id}">
|
||||||
<span>${job.title}</span>
|
<span style="${strikethrough}">${job.title}</span>
|
||||||
<span>${passing}</span>
|
<span>${passing}</span>
|
||||||
${buttons}
|
${buttons}
|
||||||
</summary>
|
</summary>
|
||||||
<table>
|
<table>
|
||||||
<tr><td>
|
<tr><td>
|
||||||
<code>${job.cron}</code>
|
<code style="${strikethrough}">${job.cron}</code>
|
||||||
<code>${job.language}</code>
|
<code>${job.language}</code>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
<tr><td>
|
<tr><td>
|
||||||
|
|
@ -126,7 +132,14 @@ function jobmodify(input) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function jobdelete(input) {
|
function jobdelete(input) {
|
||||||
http("DELETE", "/api/job/delete", cb, null)
|
var job = jobFromInput(input)
|
||||||
|
if (!confirm(`Delete the job "${job.title}"?`))
|
||||||
|
return
|
||||||
|
function cb(body, status) {
|
||||||
|
var tr = getJobElement(job.id)
|
||||||
|
tr.parentNode.removeChild(tr)
|
||||||
|
}
|
||||||
|
http("DELETE", "/api/job/delete/"+job.id, cb, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
function jobrefresh(input) {
|
function jobrefresh(input) {
|
||||||
|
|
@ -154,6 +167,20 @@ function jobrefresh(input) {
|
||||||
http("GET", "/api/job/get/"+job.id, cb, null)
|
http("GET", "/api/job/get/"+job.id, cb, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getJobElement(id) {
|
||||||
|
var table = getJobsTable()
|
||||||
|
var summaries = Array.from(table.getElementsByTagName("summary"))
|
||||||
|
var target = null
|
||||||
|
summaries.forEach(function(e) {
|
||||||
|
if (e.getAttribute("name") == id) {
|
||||||
|
e = e.parentElement
|
||||||
|
e = e.parentElement.parentElement
|
||||||
|
target = e
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return target
|
||||||
|
}
|
||||||
|
|
||||||
function jobFromInput(input) {
|
function jobFromInput(input) {
|
||||||
var b64 = input.getAttribute("job")
|
var b64 = input.getAttribute("job")
|
||||||
var json = atob(b64)
|
var json = atob(b64)
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,9 @@ func newBashJob(schedule, sh string, title ...string) (*Job, error) {
|
||||||
j.Title = title[0]
|
j.Title = title[0]
|
||||||
}
|
}
|
||||||
j.foo = func() {
|
j.foo = func() {
|
||||||
|
if j.Disabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
cmd := exec.Command("bash", "-c", sh)
|
cmd := exec.Command("bash", "-c", sh)
|
||||||
j.LastRun = time.Now()
|
j.LastRun = time.Now()
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"local/firestormy/config"
|
||||||
|
"local/firestormy/config/ns"
|
||||||
|
"local/firestormy/scheduler"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) disable(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.setDisabled(w, r, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) enable(w http.ResponseWriter, r *http.Request) {
|
||||||
|
s.setDisabled(w, r, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) setDisabled(w http.ResponseWriter, r *http.Request, disabled bool) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
j.Disabled = disabled
|
||||||
|
|
||||||
|
if err := scheduler.Schedule.Update(j); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Write([]byte("{}"))
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"local/firestormy/config"
|
||||||
|
"local/firestormy/config/ns"
|
||||||
|
"local/firestormy/scheduler"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) delete(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
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scheduler.Schedule.Remove(j); err != nil {
|
||||||
|
if err := j.Decode(b); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w.Write([]byte("{}"))
|
||||||
|
}
|
||||||
|
|
@ -24,6 +24,18 @@ func (s *Server) Routes() error {
|
||||||
path: fmt.Sprintf("/api/job/list"),
|
path: fmt.Sprintf("/api/job/list"),
|
||||||
handler: s.gzip(s.authenticate(s.list)),
|
handler: s.gzip(s.authenticate(s.list)),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: fmt.Sprintf("/api/job/delete/%s", router.Wildcard),
|
||||||
|
handler: s.gzip(s.authenticate(s.delete)),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: fmt.Sprintf("/api/job/disable/%s", router.Wildcard),
|
||||||
|
handler: s.gzip(s.authenticate(s.disable)),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: fmt.Sprintf("/api/job/enable/%s", router.Wildcard),
|
||||||
|
handler: s.gzip(s.authenticate(s.enable)),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: fmt.Sprintf("%s%s", wildcard, wildcard),
|
path: fmt.Sprintf("%s%s", wildcard, wildcard),
|
||||||
handler: s.gzip(s.authenticate(s.static)),
|
handler: s.gzip(s.authenticate(s.static)),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue