- 迁移 1043:gateway 表加 health_status/last_check_reason/last_checked_at - Store.RecordGatewayCheck 覆盖写最近一次探活结果,Create/Update/List/Get 全量返回健康字段 - api.RecordGatewayHealthChecks 并发探 /healthz:连接失败或 5xx 判离线,其余判在线(401 等异常写入原因供排查) - workers 每 30 秒一轮,app 启动接线 - 网关管理列表新增健康状态列:在线/离线/未检查 Tag,原因与检查时间收进 Tooltip
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package workers
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.ipao.vip/rogee/creator-hub/internal/account"
|
|
"git.ipao.vip/rogee/creator-hub/internal/controlplane/api"
|
|
creatorDomain "git.ipao.vip/rogee/creator-hub/internal/creator"
|
|
"git.ipao.vip/rogee/creator-hub/internal/environment"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func RunRuntimeLeaseHeartbeat(ctx context.Context, store *environment.Store) {
|
|
ticker := time.NewTicker(20 * time.Second)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
if err := api.ReconcileRuntimeLeases(ctx, store); err != nil && ctx.Err() == nil {
|
|
logrus.WithField("service", "control-plane").WithError(err).Warn("runtime lease reconciliation failed")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func RunCreatorScheduler(ctx context.Context, store *creatorDomain.Store, accountStore *account.Store, environmentStore *environment.Store) {
|
|
api.RunCreatorScheduler(ctx, store, accountStore, environmentStore)
|
|
}
|
|
|
|
// RunGatewayHealthCheck 每 30 秒对全部注册网关探活一次,只保留最近一次结果。
|
|
func RunGatewayHealthCheck(ctx context.Context, store *environment.Store) {
|
|
ticker := time.NewTicker(30 * time.Second)
|
|
defer ticker.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-ticker.C:
|
|
if err := api.RecordGatewayHealthChecks(ctx, store); err != nil && ctx.Err() == nil {
|
|
logrus.WithField("service", "control-plane").WithError(err).Warn("gateway health check failed")
|
|
}
|
|
}
|
|
}
|
|
}
|