|
- package model
-
- import (
- "encoding/json"
- "sync"
- "time"
-
- "github.com/AFASystems/presence/internal/pkg/common/appcontext"
- "github.com/AFASystems/presence/internal/pkg/kafkaclient"
- )
-
- type BaseHealth struct {
- Lock sync.RWMutex
- Uptime time.Duration `json:"uptime"`
- ActiveReaders []string `json:"activeReaders"`
- ActiveWriters []string `json:"activeWriters"`
- ActiveBeacons []string `json:"activeBeacons"`
- }
-
- type DecoderHealth struct {
- BaseHealth
- // current active configs ? dont know yet how
- }
-
- type LocationHealth struct {
- BaseHealth
- ActiveSettings []appcontext.Settings `json:"activeSettings"`
- }
-
- type BridgeHealth struct {
- BaseHealth
- }
-
- func (b *BaseHealth) GetUptime(startTime time.Time) {
- b.Lock.Lock()
- b.Uptime = time.Since(startTime)
- b.Lock.Unlock()
- }
-
- func (b *BaseHealth) GetActiveReaders(m *kafkaclient.KafkaManager) {
- b.Lock.Lock()
- b.ActiveReaders = m.GetReaders()
- b.Lock.Unlock()
- }
-
- func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) {
- b.Lock.Lock()
- b.ActiveWriters = m.GetWriters()
- b.Lock.Unlock()
- }
-
- func (b *BaseHealth) GetActiveBeacons(m *appcontext.AppState) {
- b.Lock.Lock()
- beacons := m.GetAllBeacons()
- for beacon := range beacons {
- b.ActiveBeacons = append(b.ActiveBeacons, beacon)
- }
- b.Lock.Unlock()
- }
-
- func (d *DecoderHealth) Marshal() ([]byte, error) {
- return json.Marshal(d)
- }
-
- func (l *LocationHealth) Marshal() ([]byte, error) {
- return json.Marshal(l)
- }
-
- func (b *BridgeHealth) Marshal() ([]byte, error) {
- return json.Marshal(b)
- }
|