diff --git a/go.mod b/go.mod index 09fa39f..c5491f5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/main.go b/main.go index 195fcb2..590a058 100644 --- a/main.go +++ b/main.go @@ -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", diff --git a/queue_handlers.go b/queue_handlers.go index ce69fd5..3a726ca 100644 --- a/queue_handlers.go +++ b/queue_handlers.go @@ -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)