feat(gateway): 创建/编辑网关后立即异步探活健康状态
- POST/PUT /api/gateways 成功后后台立即探活一次 /healthz 并覆盖落库,不阻塞请求 - probeAndRecordGateway 抽出单网关探活+落库复用;探活超时改为 var 供测试注入 - 网关页保存成功后延迟 2.5s 刷新一次,尽快展示最新健康状态 - 测试:立即探活、慢网关不阻塞、不可达落 unhealthy
This commit is contained in:
@@ -132,8 +132,35 @@ func (s *memoryStore) lock(key string) func() {
|
||||
return lock.Unlock
|
||||
}
|
||||
|
||||
func (s *memoryStore) CreateGateway(_ context.Context, _, _, _ string) (hub.Gateway, error) {
|
||||
return hub.Gateway{}, nil
|
||||
func (s *memoryStore) CreateGateway(_ context.Context, name, endpoint, token string) (hub.Gateway, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if name == "" || token == "" {
|
||||
return hub.Gateway{}, hub.ErrInvalid
|
||||
}
|
||||
if s.gateways == nil {
|
||||
s.gateways = map[string]hub.Gateway{}
|
||||
}
|
||||
if _, exists := s.gateways[name]; exists {
|
||||
return hub.Gateway{}, hub.ErrConflict
|
||||
}
|
||||
gateway := hub.Gateway{Name: name, Endpoint: endpoint, Token: token}
|
||||
s.gateways[name] = gateway
|
||||
return gateway, nil
|
||||
}
|
||||
|
||||
func (s *memoryStore) RecordGatewayCheck(_ context.Context, name, status, reason string) (hub.Gateway, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
gateway, exists := s.gateways[name]
|
||||
if !exists {
|
||||
return hub.Gateway{}, hub.ErrNotFound
|
||||
}
|
||||
gateway.HealthStatus, gateway.LastCheckReason = status, reason
|
||||
now := time.Now()
|
||||
gateway.LastCheckedAt = &now
|
||||
s.gateways[name] = gateway
|
||||
return gateway, nil
|
||||
}
|
||||
func (s *memoryStore) UpdateGateway(_ context.Context, currentName, name, endpoint, token string) (hub.Gateway, error) {
|
||||
s.mu.Lock()
|
||||
|
||||
Reference in New Issue
Block a user