mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-18 18:55:54 +08:00
Add list groups REST endpoint
This commit is contained in:
parent
a2b6925041
commit
33b24ca940
@ -433,6 +433,26 @@ func toCompletedTasks(in []*asynq.TaskInfo, pf PayloadFormatter, rf ResultFormat
|
||||
return out
|
||||
}
|
||||
|
||||
type groupInfo struct {
|
||||
Group string `json:"group"`
|
||||
Size int `json:"size"`
|
||||
}
|
||||
|
||||
func toGroupInfos(in []*asynq.GroupInfo) []*groupInfo {
|
||||
out := make([]*groupInfo, len(in))
|
||||
for i, g := range in {
|
||||
out[i] = toGroupInfo(g)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func toGroupInfo(in *asynq.GroupInfo) *groupInfo {
|
||||
return &groupInfo{
|
||||
Group: in.Group,
|
||||
Size: in.Size,
|
||||
}
|
||||
}
|
||||
|
||||
type schedulerEntry struct {
|
||||
ID string `json:"id"`
|
||||
Spec string `json:"spec"`
|
||||
|
33
group_handlers.go
Normal file
33
group_handlers.go
Normal file
@ -0,0 +1,33 @@
|
||||
package asynqmon
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
|
||||
type listGroupsResponse struct {
|
||||
Groups []*groupInfo `json:"groups"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
resp := listGroupsResponse{
|
||||
Groups: toGroupInfos(groups),
|
||||
}
|
||||
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
@ -176,6 +176,9 @@ func muxRouter(opts Options, rc redis.UniversalClient, inspector *asynq.Inspecto
|
||||
|
||||
api.HandleFunc("/queues/{qname}/tasks/{task_id}", newGetTaskHandlerFunc(inspector, payloadFmt, resultFmt)).Methods("GET")
|
||||
|
||||
// Groups endponts
|
||||
api.HandleFunc("/queues/{qname}/groups", newListGroupsHandlerFunc(inspector)).Methods("GET")
|
||||
|
||||
// Servers endpoints.
|
||||
api.HandleFunc("/servers", newListServersHandlerFunc(inspector, payloadFmt)).Methods("GET")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user