mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-31 17:10:11 +08:00
Add API endpoint to delete a queue
This commit is contained in:
parent
2fa55ed6f6
commit
0d94eaaee0
2
go.mod
2
go.mod
@ -7,3 +7,5 @@ require (
|
|||||||
github.com/hibiken/asynq v0.13.1
|
github.com/hibiken/asynq v0.13.1
|
||||||
github.com/rs/cors v1.7.0
|
github.com/rs/cors v1.7.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace github.com/hibiken/asynq => ../../../database/Redis/go/asynq
|
||||||
|
2
main.go
2
main.go
@ -71,6 +71,8 @@ func main() {
|
|||||||
newListQueuesHandlerFunc(inspector)).Methods("GET")
|
newListQueuesHandlerFunc(inspector)).Methods("GET")
|
||||||
api.HandleFunc("/queues/{qname}",
|
api.HandleFunc("/queues/{qname}",
|
||||||
newGetQueueHandlerFunc(inspector)).Methods("GET")
|
newGetQueueHandlerFunc(inspector)).Methods("GET")
|
||||||
|
api.HandleFunc("/queues/{qname}",
|
||||||
|
newDeleteQueueHandlerFunc(inspector)).Methods("DELETE")
|
||||||
api.HandleFunc("/queues/{qname}/pause",
|
api.HandleFunc("/queues/{qname}/pause",
|
||||||
newPauseQueueHandlerFunc(inspector)).Methods("POST")
|
newPauseQueueHandlerFunc(inspector)).Methods("POST")
|
||||||
api.HandleFunc("/queues/{qname}/resume",
|
api.HandleFunc("/queues/{qname}/resume",
|
||||||
|
@ -58,6 +58,26 @@ func newGetQueueHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newDeleteQueueHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
qname := vars["qname"]
|
||||||
|
if err := inspector.DeleteQueue(qname, false); err != nil {
|
||||||
|
if _, ok := err.(*asynq.ErrQueueNotFound); ok {
|
||||||
|
http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, ok := err.(*asynq.ErrQueueNotEmpty); ok {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func newPauseQueueHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc {
|
func newPauseQueueHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user