Guard NewWSHub nil-db path to fix test suite flake
This commit is contained in:
@@ -121,8 +121,10 @@ type WSHub struct {
|
||||
func NewWSHub(database *db.Database) *WSHub {
|
||||
// Reset any rows that were left "online" by a previous server crash/restart.
|
||||
// Agents will re-authenticate and flip themselves back to online within seconds.
|
||||
if err := database.MarkAllAgentsOffline(); err != nil {
|
||||
log.Printf("[hub] startup offline reset: %v", err)
|
||||
if database != nil {
|
||||
if err := database.MarkAllAgentsOffline(); err != nil {
|
||||
log.Printf("[hub] startup offline reset: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
h := &WSHub{
|
||||
@@ -148,6 +150,9 @@ func NewWSHub(database *db.Database) *WSHub {
|
||||
// last_seen timestamp is stale (> 3 minutes without a stats message).
|
||||
// It also notifies the dashboard so client state stays in sync.
|
||||
func (h *WSHub) runStaleAgentSweep() {
|
||||
if h.db == nil {
|
||||
return
|
||||
}
|
||||
const staleness = 3 * time.Minute
|
||||
ticker := time.NewTicker(45 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
Reference in New Issue
Block a user