MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / taskRoute

Function taskRoute

server/handles/task.go:127–218  ·  view source on GitHub ↗
(g *gin.RouterGroup, manager task.Manager[T])

Source from the content-addressed store, hash-verified

125}
126
127func taskRoute[T task.TaskExtensionInfo](g *gin.RouterGroup, manager task.Manager[T]) {
128 g.GET("/undone", func(c *gin.Context) {
129 isAdmin, uid, ok := getUserInfo(c)
130 if !ok {
131 // if there is no bug, here is unreachable
132 common.ErrorStrResp(c, "user invalid", 401)
133 return
134 }
135 common.SuccessResp(c, getTaskInfos(manager.GetByCondition(func(task T) bool {
136 // avoid directly passing the user object into the function to reduce closure size
137 return (isAdmin || uid == task.GetCreator().ID) &&
138 argsContains(task.GetState(), tache.StatePending, tache.StateRunning, tache.StateCanceling,
139 tache.StateErrored, tache.StateFailing, tache.StateWaitingRetry, tache.StateBeforeRetry)
140 })))
141 })
142 g.GET("/done", func(c *gin.Context) {
143 isAdmin, uid, ok := getUserInfo(c)
144 if !ok {
145 // if there is no bug, here is unreachable
146 common.ErrorStrResp(c, "user invalid", 401)
147 return
148 }
149 common.SuccessResp(c, getTaskInfos(manager.GetByCondition(func(task T) bool {
150 return (isAdmin || uid == task.GetCreator().ID) &&
151 argsContains(task.GetState(), tache.StateCanceled, tache.StateFailed, tache.StateSucceeded)
152 })))
153 })
154 g.POST("/info", getTargetedHandler(manager, func(c *gin.Context, task T) {
155 common.SuccessResp(c, getTaskInfo(task))
156 }))
157 g.POST("/cancel", getTargetedHandler(manager, func(c *gin.Context, task T) {
158 manager.Cancel(task.GetID())
159 common.SuccessResp(c)
160 }))
161 g.POST("/delete", getTargetedHandler(manager, func(c *gin.Context, task T) {
162 manager.Remove(task.GetID())
163 common.SuccessResp(c)
164 }))
165 g.POST("/retry", getTargetedHandler(manager, func(c *gin.Context, task T) {
166 manager.Retry(task.GetID())
167 common.SuccessResp(c)
168 }))
169 g.POST("/cancel_some", getBatchHandler(manager, func(task T) {
170 manager.Cancel(task.GetID())
171 }))
172 g.POST("/delete_some", getBatchHandler(manager, func(task T) {
173 manager.Remove(task.GetID())
174 }))
175 g.POST("/retry_some", getBatchHandler(manager, func(task T) {
176 manager.Retry(task.GetID())
177 }))
178 g.POST("/clear_done", func(c *gin.Context) {
179 isAdmin, uid, ok := getUserInfo(c)
180 if !ok {
181 // if there is no bug, here is unreachable
182 common.ErrorStrResp(c, "user invalid", 401)
183 return
184 }

Callers 1

SetupTaskRouteFunction · 0.85

Calls 15

ErrorStrRespFunction · 0.92
SuccessRespFunction · 0.92
getUserInfoFunction · 0.85
getTaskInfosFunction · 0.85
argsContainsFunction · 0.85
getTargetedHandlerFunction · 0.85
getTaskInfoFunction · 0.85
getBatchHandlerFunction · 0.85
GetByConditionMethod · 0.80
GetStateMethod · 0.80
GetCreatorMethod · 0.65
CancelMethod · 0.65

Tested by

no test coverage detected