Skip to content

Commit

Permalink
feat(task): add clear succeeded and retry (#3856 close #3776)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rektyfikowany authored Mar 16, 2023
1 parent a1e88cf commit 8c0defc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/task/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions server/handles/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8c0defc

Please sign in to comment.