asynqmon/server_handlers.go

35 lines
897 B
Go
Raw Normal View History

package asynqmon
import (
"encoding/json"
"net/http"
2021-05-29 05:40:09 +08:00
"github.com/hibiken/asynq"
)
// ****************************************************************************
// This file defines:
// - http.Handler(s) for server related endpoints
// ****************************************************************************
2021-10-04 23:18:00 +08:00
type listServersResponse struct {
Servers []*serverInfo `json:"servers"`
}
func newListServersHandlerFunc(inspector *asynq.Inspector, pf PayloadFormatter) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
srvs, err := inspector.Servers()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
2021-10-04 23:18:00 +08:00
resp := listServersResponse{
Servers: toServerInfoList(srvs, pf),
}
if err := json.NewEncoder(w).Encode(resp); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
}