2021-09-18 20:25:59 +08:00
|
|
|
package asynqmon
|
2020-12-31 00:58:50 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2021-05-29 05:40:09 +08:00
|
|
|
"github.com/hibiken/asynq"
|
2020-12-31 00:58:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// This file defines:
|
|
|
|
// - http.Handler(s) for server related endpoints
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
type ListServersResponse struct {
|
|
|
|
Servers []*ServerInfo `json:"servers"`
|
|
|
|
}
|
|
|
|
|
2021-09-18 20:26:00 +08:00
|
|
|
func newListServersHandlerFunc(inspector *asynq.Inspector, t *transformer) http.HandlerFunc {
|
2020-12-31 00:58:50 +08:00
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
srvs, err := inspector.Servers()
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp := ListServersResponse{
|
2021-09-18 20:26:00 +08:00
|
|
|
Servers: t.toServerInfoList(srvs),
|
2020-12-31 00:58:50 +08:00
|
|
|
}
|
|
|
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|