Browse Source

fix: add pool status to health check api

Yeuoly 9 months ago
parent
commit
bc936bf807
2 changed files with 20 additions and 2 deletions
  1. 6 2
      internal/server/controllers/health_check.go
  2. 14 0
      internal/utils/routine/pool.go

+ 6 - 2
internal/server/controllers/health_check.go

@@ -1,7 +1,11 @@
 package controllers
 
-import "github.com/gin-gonic/gin"
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/langgenius/dify-plugin-daemon/internal/utils/routine"
+)
 
 func HealthCheck(c *gin.Context) {
-	c.JSON(200, gin.H{"status": "ok"})
+	routine.InitPool(10)
+	c.JSON(200, gin.H{"status": "ok", "pool_status": routine.FetchRoutineStatus()})
 }

+ 14 - 0
internal/utils/routine/pool.go

@@ -66,3 +66,17 @@ func WithMaxRoutine(max_routine int, tasks []func(), on_finish ...func()) {
 		}
 	})
 }
+
+type PoolStatus struct {
+	Free  int `json:"free"`
+	Busy  int `json:"busy"`
+	Total int `json:"total"`
+}
+
+func FetchRoutineStatus() *PoolStatus {
+	return &PoolStatus{
+		Free:  p.Free(),
+		Busy:  p.Running(),
+		Total: p.Cap(),
+	}
+}