Skip to content

Commit 75706b4

Browse files
committed
chore(server): status api for monitor
1 parent 8fee06b commit 75706b4

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎pkg/server/admin_s.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package server
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gin-gonic/gin"
7+
)
8+
9+
type UploadStats struct {
10+
FuncUnitTodo int `json:"funcUnitTodo"`
11+
FuncCtxUnitTodo int `json:"funcCtxUnitTodo"`
12+
}
13+
14+
// @Summary upload status query
15+
// @Produce json
16+
// @Success 200
17+
// @Router /api/v1/monitor/upload [get]
18+
func HandleStatusUpload(c *gin.Context) {
19+
stat := &UploadStats{
20+
FuncUnitTodo: len(funcUnitQueue),
21+
FuncCtxUnitTodo: len(funcCtxUnitQueue),
22+
}
23+
c.JSON(http.StatusOK, stat)
24+
}

‎pkg/server/app.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ func Execute(config ExecuteConfig) {
7878
engine.Handle(http.MethodGet, "/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
7979

8080
v1group := engine.Group("/api/v1")
81+
// query
8182
v1group.Handle(http.MethodGet, "/repo", HandleRepoQuery)
8283
v1group.Handle(http.MethodGet, "/rev", HandleRevQuery)
8384
v1group.Handle(http.MethodGet, "/file", HandleFileQuery)
8485
v1group.Handle(http.MethodGet, "/func", HandleFunctionsQuery)
8586
v1group.Handle(http.MethodGet, "/funcctx", HandleFunctionCtxQuery)
86-
87+
// upload
8788
v1group.Handle(http.MethodPost, "/func", HandleRepoFuncUpload)
8889
v1group.Handle(http.MethodPost, "/funcctx", HandleFunctionContextUpload)
90+
// admin
91+
v1group.Handle(http.MethodGet, "/monitor/upload", HandleStatusUpload)
8992

9093
err := engine.Run(fmt.Sprintf(":%d", 9876))
9194
if err != nil {

0 commit comments

Comments
 (0)
⌂ 换网址