2022-03-24 21:54:41 +08:00
|
|
|
package asynqmon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/hibiken/asynq"
|
|
|
|
)
|
|
|
|
|
|
|
|
type listGroupsResponse struct {
|
2022-04-02 02:57:00 +08:00
|
|
|
Queue *queueStateSnapshot `json:"stats"`
|
|
|
|
Groups []*groupInfo `json:"groups"`
|
2022-03-24 21:54:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func newListGroupsHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
qname := mux.Vars(r)["qname"]
|
|
|
|
|
|
|
|
groups, err := inspector.Groups(qname)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
2022-04-02 02:57:00 +08:00
|
|
|
qinfo, err := inspector.GetQueueInfo(qname)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
2022-03-24 21:54:41 +08:00
|
|
|
|
|
|
|
resp := listGroupsResponse{
|
2022-04-02 02:57:00 +08:00
|
|
|
Queue: toQueueStateSnapshot(qinfo),
|
2022-03-24 21:54:41 +08:00
|
|
|
Groups: toGroupInfos(groups),
|
|
|
|
}
|
|
|
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|