diff --git a/main.go b/main.go index 5c5fea3..fdf2717 100644 --- a/main.go +++ b/main.go @@ -79,6 +79,8 @@ func main() { newResumeQueueHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/active_tasks", newListActiveTasksHandlerFunc(inspector)).Methods("GET") + api.HandleFunc("/queues/{qname}/active_tasks/{task_id}/cancel", + newCancelActiveTaskHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/pending_tasks", newListPendingTasksHandlerFunc(inspector)).Methods("GET") api.HandleFunc("/queues/{qname}/scheduled_tasks", diff --git a/task_handlers.go b/task_handlers.go index 59e6de3..4921d3d 100644 --- a/task_handlers.go +++ b/task_handlers.go @@ -42,6 +42,17 @@ func newListActiveTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc } } +func newCancelActiveTaskHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + id := mux.Vars(r)["task_id"] + if err := inspector.CancelActiveTask(id); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusNoContent) + } +} + func newListPendingTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r)