feat: complete 2.0.7.12 platform overhaul
This commit is contained in:
@@ -1,20 +1,55 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"ymhut-box/server/unified-management/internal/config"
|
||||
"ymhut-box/server/unified-management/internal/db"
|
||||
)
|
||||
|
||||
func Snapshot(cfg *config.Config, store *db.Store) map[string]any {
|
||||
type Service struct {
|
||||
cfg *config.Config
|
||||
store *db.Store
|
||||
mu sync.RWMutex
|
||||
checks []config.Check
|
||||
checkedAt time.Time
|
||||
}
|
||||
|
||||
func NewService(cfg *config.Config, store *db.Store) *Service {
|
||||
service := &Service{cfg: cfg, store: store}
|
||||
service.RefreshPreflight()
|
||||
return service
|
||||
}
|
||||
|
||||
func (s *Service) RefreshPreflight() []config.Check {
|
||||
checks := config.Preflight(s.cfg)
|
||||
s.mu.Lock()
|
||||
s.checks = append([]config.Check(nil), checks...)
|
||||
s.checkedAt = time.Now().UTC()
|
||||
s.mu.Unlock()
|
||||
return checks
|
||||
}
|
||||
|
||||
func (s *Service) Snapshot() map[string]any {
|
||||
s.mu.RLock()
|
||||
checks := append([]config.Check(nil), s.checks...)
|
||||
checkedAt := s.checkedAt
|
||||
s.mu.RUnlock()
|
||||
return map[string]any{
|
||||
"ok": true,
|
||||
"version": config.Version,
|
||||
"service": map[string]any{
|
||||
"name": "YMhut Unified Management",
|
||||
"baseUrl": cfg.BaseURL,
|
||||
"cdnBaseUrl": cfg.CDNBaseURL,
|
||||
"baseUrl": s.cfg.BaseURL,
|
||||
"cdnBaseUrl": s.cfg.CDNBaseURL,
|
||||
},
|
||||
"database": store.Status(),
|
||||
"preflight": config.Preflight(cfg),
|
||||
"database": s.store.Status(),
|
||||
"preflight": checks,
|
||||
"preflightCheckedAt": checkedAt.Format(time.RFC3339),
|
||||
}
|
||||
}
|
||||
|
||||
func Snapshot(cfg *config.Config, store *db.Store) map[string]any {
|
||||
return NewService(cfg, store).Snapshot()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user