diff --git a/httpserver.go b/httpserver.go index 2aef4ec..5651d19 100644 --- a/httpserver.go +++ b/httpserver.go @@ -12,6 +12,7 @@ import ( func httpServer(listenAddress string) { http.HandleFunc("/", handler) + http.HandleFunc("/reloadJobs", handleReloadJobs) http.HandleFunc("/shutdown", handleShutdown) http.HandleFunc("/start", handleForceStart) log.WithField("job", "http_server").Fatal(http.ListenAndServe(listenAddress, nil)) @@ -23,7 +24,7 @@ func handler(w http.ResponseWriter, r *http.Request) { return } - currentRunningJobsMutex.RLock() + globalMutex.RLock() buf := new(bytes.Buffer) jobEntries := c.Entries() var jobs []*Job @@ -31,7 +32,7 @@ func handler(w http.ResponseWriter, r *http.Request) { jobs = append(jobs, v.Job.(*Job)) } indexTemplate.ExecuteTemplate(buf, "index", jobs) - currentRunningJobsMutex.RUnlock() + globalMutex.RUnlock() buf.WriteTo(w) } @@ -69,3 +70,24 @@ func handleShutdown(w http.ResponseWriter, r *http.Request) { os.Exit(0) }() } + +func handleReloadJobs(w http.ResponseWriter, r *http.Request) { + globalMutex.Lock() + defer globalMutex.Unlock() + + c.Stop() + + for _, entry := range c.Entries() { + c.Remove(entry.ID) + } + + err := initJobs() + if err != nil { + http.Error(w, fmt.Sprintf("reload jobs error: %v", err), http.StatusInternalServerError) + return + } + + c.Start() + + http.Redirect(w, r, "/", http.StatusTemporaryRedirect) +} diff --git a/index.htm b/index.htm index cb2cb83..4a3fbcf 100644 --- a/index.htm +++ b/index.htm @@ -150,6 +150,7 @@ padding: 0.5em; text-decoration: none; display: block; + white-space: nowrap; } .dropdown:hover .dropdown-content { @@ -163,7 +164,11 @@