mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-10-23 12:12:37 +00:00
feat(ingest): use last seen in observer online check
now uses last seen (packet message) as well as last status (status message) as indicators of observer being online or not
This commit is contained in:
4 files changed
+8
-7
No files matched your search
+2
-1
@@ -140,7 +140,8 @@ func (s *Store) GetObserver(ctx context.Context, observerID uuid.UUID) (*api.Obs
|
||||
})
|
||||
}
|
||||
observer.Brokers = brokers
|
||||
if obs.LastStatusAt.Valid && time.Since(obs.LastStatusAt.Time) < 5*time.Minute {
|
||||
if (obs.LastStatusAt.Valid && time.Since(obs.LastStatusAt.Time) < 5*time.Minute) ||
|
||||
(obs.LastSeen.Valid && time.Since(obs.LastSeen.Time) < 5*time.Minute) {
|
||||
observer.Status = "online"
|
||||
}
|
||||
var lastStatusAt *int64
|
||||
|
||||
@@ -184,7 +184,7 @@ func TestGetObserver_OnlineStatus(t *testing.T) {
|
||||
PublicKey: []byte{0x01},
|
||||
ObservationCount: &obsCount,
|
||||
FirstSeen: pgtype.Timestamptz{Time: time.Now().Add(-time.Hour), Valid: true},
|
||||
LastSeen: pgtype.Timestamptz{Time: time.Now(), Valid: true},
|
||||
LastSeen: pgtype.Timestamptz{Time: time.Now().Add(-time.Minute), Valid: true},
|
||||
LastStatusAt: pgtype.Timestamptz{Time: time.Now().Add(-time.Minute), Valid: true},
|
||||
}, nil)
|
||||
|
||||
@@ -227,7 +227,7 @@ func TestGetObserver_OfflineStatus(t *testing.T) {
|
||||
PublicKey: []byte{0x01},
|
||||
ObservationCount: &obsCount,
|
||||
FirstSeen: pgtype.Timestamptz{Time: time.Now().Add(-time.Hour), Valid: true},
|
||||
LastSeen: pgtype.Timestamptz{Time: time.Now(), Valid: true},
|
||||
LastSeen: pgtype.Timestamptz{Time: time.Now().Add(-10 * time.Minute), Valid: true},
|
||||
LastStatusAt: pgtype.Timestamptz{Time: time.Now().Add(-10 * time.Minute), Valid: true},
|
||||
}, nil)
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ SELECT
|
||||
o.radio_bw_khz,
|
||||
array_remove(array_agg(DISTINCT ts.name ORDER BY ts.name), NULL)::text[] AS scopes,
|
||||
COALESCE(CASE
|
||||
WHEN o.last_status_at > NOW() - INTERVAL '5 minutes' THEN 'online'
|
||||
WHEN GREATEST(COALESCE(o.last_status_at, o.last_seen), o.last_seen) > NOW() - INTERVAL '5 minutes' THEN 'online'
|
||||
ELSE 'offline'
|
||||
END, 'offline')::text AS status,
|
||||
COALESCE((
|
||||
@@ -169,7 +169,7 @@ WHERE
|
||||
AND ($2 = '' OR o.observer_type = $2)
|
||||
AND ($3 = '' OR ob.broker_name = $3)
|
||||
AND ($4 = '' OR CASE
|
||||
WHEN o.last_status_at > NOW() - INTERVAL '5 minutes' THEN 'online'
|
||||
WHEN GREATEST(COALESCE(o.last_status_at, o.last_seen), o.last_seen) > NOW() - INTERVAL '5 minutes' THEN 'online'
|
||||
ELSE 'offline'
|
||||
END = $4)
|
||||
AND ($5 = '' OR o.display_name ILIKE '%' || $5 || '%')
|
||||
|
||||
@@ -2279,7 +2279,7 @@ SELECT
|
||||
o.radio_bw_khz,
|
||||
array_remove(array_agg(DISTINCT ts.name ORDER BY ts.name), NULL)::text[] AS scopes,
|
||||
COALESCE(CASE
|
||||
WHEN o.last_status_at > NOW() - INTERVAL '5 minutes' THEN 'online'
|
||||
WHEN GREATEST(COALESCE(o.last_status_at, o.last_seen), o.last_seen) > NOW() - INTERVAL '5 minutes' THEN 'online'
|
||||
ELSE 'offline'
|
||||
END, 'offline')::text AS status,
|
||||
COALESCE((
|
||||
@@ -2302,7 +2302,7 @@ WHERE
|
||||
AND ($2 = '' OR o.observer_type = $2)
|
||||
AND ($3 = '' OR ob.broker_name = $3)
|
||||
AND ($4 = '' OR CASE
|
||||
WHEN o.last_status_at > NOW() - INTERVAL '5 minutes' THEN 'online'
|
||||
WHEN GREATEST(COALESCE(o.last_status_at, o.last_seen), o.last_seen) > NOW() - INTERVAL '5 minutes' THEN 'online'
|
||||
ELSE 'offline'
|
||||
END = $4)
|
||||
AND ($5 = '' OR o.display_name ILIKE '%' || $5 || '%')
|
||||
|
||||
Reference in new issue
Block a user