Commit d779743e authored by ale's avatar ale

Move debugging code to top-level package

parent eaa119ca
......@@ -44,14 +44,14 @@ func NewAgent(ctx context.Context, configMgr *ConfigManager, ms MetadataStore) (
}
// Close the Agent and all associated resources.
func (d *Agent) Close() {
d.mgr.Close() // nolint
d.sched.Stop()
func (a *Agent) Close() {
a.mgr.Close() // nolint
a.sched.Stop()
}
func (d *Agent) startHTTPServer(addr string) error {
//http.Handle("/debug/jobs", d.mgr.StateManager)
http.Handle("/debug/sched", d.sched)
func (a *Agent) startHTTPServer(addr string) error {
http.HandleFunc("/debug/jobs", a.handleStateManagerDebug)
http.HandleFunc("/debug/sched", a.handleSchedulerDebug)
go http.ListenAndServe(addr, nil)
return nil
}
......
......@@ -130,4 +130,7 @@ type Manager interface {
RestoreJob(context.Context, FindRequest, string) (jobs.Job, error)
Restore(context.Context, FindRequest, string) error
Close() error
// Debug interface.
GetStatus() ([]jobs.Status, []jobs.Status, []jobs.Status)
}
package jobs
package tabacco
import (
"html/template"
......@@ -112,8 +112,8 @@ func init() {
// ServeHTTP implements the job status debug handler, by making the
// stateManager object match the http.Handler interface.
func (j *StateManager) ServeHTTP(w http.ResponseWriter, r *http.Request) {
pending, running, done := j.getStatus()
func (a *Agent) handleStateManagerDebug(w http.ResponseWriter, r *http.Request) {
pending, running, done := a.mgr.GetStatus()
w.Header().Set("Content-Type", "text/html")
_ = debugTpl.Lookup("state_manager_debug_page").Execute(w, map[string]interface{}{
......@@ -128,9 +128,9 @@ func (j *StateManager) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// ServeHTTP implements the job status debug handler, by making the
// stateManager object match the http.Handler interface.
func (s *Scheduler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (a *Agent) handleSchedulerDebug(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
_ = debugTpl.Lookup("scheduler_debug_page").Execute(w, map[string]interface{}{
"Schedule": s.getStatus(),
"Schedule": a.sched.GetStatus(),
})
}
......@@ -340,7 +340,7 @@ func jobStatusListToSlice(l *list.List) []Status {
// GetStatus returns three lists of Status objects, representing
// respectively pending jobs (waiting to run), running jobs, and
// completed jobs (ordered by decreasing timestamp).
func (m *StateManager) getStatus() ([]Status, []Status, []Status) {
func (m *StateManager) GetStatus() ([]Status, []Status, []Status) {
m.mx.Lock()
defer m.mx.Unlock()
......
......@@ -213,8 +213,8 @@ func cronJobStatusListOrderByName(list []CronJobStatus) *cronJobStatusList {
}
}
// getStatus returns the current status of the scheduled jobs.
func (s *Scheduler) getStatus() []CronJobStatus {
// GetStatus returns the current status of the scheduled jobs.
func (s *Scheduler) GetStatus() []CronJobStatus {
s.mx.Lock()
defer s.mx.Unlock()
if s.cur == nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment