mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-09-22 06:46:34 +08:00
Add ListSchedulerEntries API endpoint
This commit is contained in:
31
scheduler_entry_handlers.go
Normal file
31
scheduler_entry_handlers.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/hibiken/asynq"
|
||||
)
|
||||
|
||||
// ****************************************************************************
|
||||
// This file defines:
|
||||
// - http.Handler(s) for scheduler entry related endpoints
|
||||
// ****************************************************************************
|
||||
|
||||
func newListSchedulerEntriesHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
entries, err := inspector.SchedulerEntries()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
payload := make(map[string]interface{})
|
||||
if len(entries) == 0 {
|
||||
// avoid nil for the entries field in json output.
|
||||
payload["entries"] = make([]*SchedulerEntry, 0)
|
||||
} else {
|
||||
payload["entries"] = toSchedulerEntries(entries)
|
||||
}
|
||||
json.NewEncoder(w).Encode(payload)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user