feat(task): add clear succeeded and retry (#3856 close #3776)

pull/3874/head
Brian 2023-03-16 15:56:27 +08:00 committed by GitHub
parent a1e88cfa05
commit 8c0defce09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -122,6 +122,10 @@ func (tm *Manager[K]) ClearDone() {
tm.RemoveByStates(SUCCEEDED, CANCELED, ERRORED)
}
func (tm *Manager[K]) ClearSucceeded() {
tm.RemoveByStates(SUCCEEDED)
}
func (tm *Manager[K]) RawTasks() *generic_sync.MapOf[K, *Task[K]] {
return &tm.tasks
}

View File

@ -92,10 +92,27 @@ func taskRoute[K comparable](g *gin.RouterGroup, manager *task.Manager[K], k2Str
common.SuccessResp(c)
}
})
g.POST("/retry", func(c *gin.Context) {
tid := c.Query("tid")
id, err := str2K(tid)
if err != nil {
common.ErrorResp(c, err, 400)
return
}
if err := manager.Retry(id); err != nil {
common.ErrorResp(c, err, 500)
} else {
common.SuccessResp(c)
}
})
g.POST("/clear_done", func(c *gin.Context) {
manager.ClearDone()
common.SuccessResp(c)
})
g.POST("/clear_succeeded", func(c *gin.Context) {
manager.ClearSucceeded()
common.SuccessResp(c)
})
}
func SetupTaskRoute(g *gin.RouterGroup) {