Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Extract fleet caps (128 hosts, sem=16, 250ms coalesce, syscheck=20) into named constants with Go tests; wire ListStaleOnlineAgents for stale sweeps instead of full ListAgents scans.
31 lines
770 B
Go
31 lines
770 B
Go
package db
|
|
|
|
import (
|
|
"time"
|
|
|
|
"crypto-miner-server/internal/models"
|
|
)
|
|
|
|
// ListStaleOnlineAgents returns online agents whose last_seen is older than
|
|
// the given threshold. Uses indexed status+last_seen filters instead of a full
|
|
// table scan.
|
|
func (d *Database) ListStaleOnlineAgents(olderThan time.Duration) ([]*models.Agent, error) {
|
|
cutoff := time.Now().Add(-olderThan)
|
|
query := `SELECT ` + agentSelectCols + ` FROM agents WHERE status = 'online' AND last_seen < ? ORDER BY last_seen ASC`
|
|
rows, err := d.Query(query, cutoff)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var agents []*models.Agent
|
|
for rows.Next() {
|
|
a, err := d.scanAgent(rows)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
agents = append(agents, a)
|
|
}
|
|
return agents, rows.Err()
|
|
}
|