Add titles to config file and sort list by title

master
bel 2020-03-15 17:05:29 +00:00
parent 9d51626e4b
commit 2f31b4624a
6 changed files with 12 additions and 9 deletions

View File

@ -46,7 +46,7 @@ func newBashJob(schedule, sh string, title ...string) (*Job, error) {
Raw: sh,
Runner: Bash,
}
if len(title) == 0 {
if len(title) == 0 || len(title[0]) == 0 {
j.Title = j.Name
} else {
j.Title = title[0]

View File

@ -93,6 +93,7 @@ func splitScheduleCommandTitle(b []byte) (string, string, string) {
if i := strings.LastIndex(commandTitle, "#"); i >= 0 {
title = commandTitle[i+1:]
}
title = strings.TrimSpace(title)
return schedule, commandTitle, title
}

View File

@ -16,7 +16,6 @@ func (s *Server) list(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
sort.Strings(jobs)
out := make([]map[string]interface{}, len(jobs))
for i, job := range jobs {
out[i] = make(map[string]interface{})
@ -46,5 +45,8 @@ func (s *Server) list(w http.ResponseWriter, r *http.Request) {
"status": j.LastStatus,
}
}
sort.Slice(out, func(i, j int) bool {
return out[i]["title"].(string) < out[j]["title"].(string)
})
json.NewEncoder(w).Encode(out)
}

10
testdata/5_jobs.cron vendored
View File

@ -1,5 +1,5 @@
0 */5 * * * * echo first job
0 */15 * * * * echo second job
0 */25 * * * * echo third job
0 */35 * * * * echo fourth job
0 */45 * * * * true
0 */5 * * * * echo first job #first job; every 5m
0 */15 * * * * echo second job # second job; every 15m
0 */25 * * * * echo third job #### third job; every 25m
0 */35 * * * * echo fourth job #4th job; ever 35m
0 */45 * * * * true

View File

@ -1 +1 @@
0 */5 * * * * hostname
0 */5 * * * * hostname #hostname every 5m

View File

@ -1 +1 @@
* * * * * * hostname
* * * * * * hostname #hostname per sec