Add API endpoint to delete a queue

This commit is contained in:
Ken Hibino 2020-11-27 22:32:05 -08:00
parent 2fa55ed6f6
commit 0d94eaaee0
3 changed files with 24 additions and 0 deletions

2
go.mod
View File

@ -7,3 +7,5 @@ require (
github.com/hibiken/asynq v0.13.1
github.com/rs/cors v1.7.0
)
replace github.com/hibiken/asynq => ../../../database/Redis/go/asynq

View File

@ -71,6 +71,8 @@ func main() {
newListQueuesHandlerFunc(inspector)).Methods("GET")
api.HandleFunc("/queues/{qname}",
newGetQueueHandlerFunc(inspector)).Methods("GET")
api.HandleFunc("/queues/{qname}",
newDeleteQueueHandlerFunc(inspector)).Methods("DELETE")
api.HandleFunc("/queues/{qname}/pause",
newPauseQueueHandlerFunc(inspector)).Methods("POST")
api.HandleFunc("/queues/{qname}/resume",

View File

@ -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 {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)