From 4d5de30a578a9fbeae5bb20f7dabd9c46e216b46 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Wed, 16 Dec 2020 07:35:36 -0800 Subject: [PATCH] Add API endpoint to run all dead tasks --- main.go | 1 + task_handlers.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/main.go b/main.go index 40edbff..73ebad6 100644 --- a/main.go +++ b/main.go @@ -94,6 +94,7 @@ func main() { api.HandleFunc("/queues/{qname}/dead_tasks:delete_all", newDeleteAllDeadTasksHandlerFunc(inspector)).Methods("DELETE") api.HandleFunc("/queues/{qname}/dead_tasks:batch_delete", newBatchDeleteDeadTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/dead_tasks/{task_key}:run", newRunTaskHandlerFunc(inspector)).Methods("POST") + api.HandleFunc("/queues/{qname}/dead_tasks:run_all", newRunAllDeadTasksHandlerFunc(inspector)).Methods("POST") api.HandleFunc("/queues/{qname}/dead_tasks:batch_run", newBatchRunTasksHandlerFunc(inspector)).Methods("POST") // Scheduler Entry endpoints. diff --git a/task_handlers.go b/task_handlers.go index a53fe21..27668a0 100644 --- a/task_handlers.go +++ b/task_handlers.go @@ -248,6 +248,17 @@ func newDeleteAllDeadTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFu } } +func newRunAllDeadTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + qname := mux.Vars(r)["qname"] + if _, err := inspector.RunAllDeadTasks(qname); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.WriteHeader(http.StatusNoContent) + } +} + // request body used for all batch delete tasks endpoints. type batchDeleteTasksRequest struct { TaskKeys []string `json:"task_keys"`