mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-18 18:55:54 +08:00
Add API endpoint to cancel active task
This commit is contained in:
parent
96eec9ce11
commit
47d8c73ab7
2
main.go
2
main.go
@ -79,6 +79,8 @@ func main() {
|
|||||||
newResumeQueueHandlerFunc(inspector)).Methods("POST")
|
newResumeQueueHandlerFunc(inspector)).Methods("POST")
|
||||||
api.HandleFunc("/queues/{qname}/active_tasks",
|
api.HandleFunc("/queues/{qname}/active_tasks",
|
||||||
newListActiveTasksHandlerFunc(inspector)).Methods("GET")
|
newListActiveTasksHandlerFunc(inspector)).Methods("GET")
|
||||||
|
api.HandleFunc("/queues/{qname}/active_tasks/{task_id}/cancel",
|
||||||
|
newCancelActiveTaskHandlerFunc(inspector)).Methods("POST")
|
||||||
api.HandleFunc("/queues/{qname}/pending_tasks",
|
api.HandleFunc("/queues/{qname}/pending_tasks",
|
||||||
newListPendingTasksHandlerFunc(inspector)).Methods("GET")
|
newListPendingTasksHandlerFunc(inspector)).Methods("GET")
|
||||||
api.HandleFunc("/queues/{qname}/scheduled_tasks",
|
api.HandleFunc("/queues/{qname}/scheduled_tasks",
|
||||||
|
@ -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 {
|
func newListPendingTasksHandlerFunc(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…
Reference in New Issue
Block a user