update project structure

- move agent to /agent
- change /beszel to /src
- update workflows and docker builds
This commit is contained in:
henrygd
2025-09-07 16:42:15 -04:00
parent 4e26defdca
commit 6f5d95031c
212 changed files with 258 additions and 216 deletions

37
agent/agent_cache.go Normal file
View File

@@ -0,0 +1,37 @@
package agent
import (
"time"
"github.com/henrygd/beszel/src/entities/system"
)
// Not thread safe since we only access from gatherStats which is already locked
type SessionCache struct {
data *system.CombinedData
lastUpdate time.Time
primarySession string
leaseTime time.Duration
}
func NewSessionCache(leaseTime time.Duration) *SessionCache {
return &SessionCache{
leaseTime: leaseTime,
data: &system.CombinedData{},
}
}
func (c *SessionCache) Get(sessionID string) (stats *system.CombinedData, isCached bool) {
if sessionID != c.primarySession && time.Since(c.lastUpdate) < c.leaseTime {
return c.data, true
}
return c.data, false
}
func (c *SessionCache) Set(sessionID string, data *system.CombinedData) {
if data != nil {
*c.data = *data
}
c.primarySession = sessionID
c.lastUpdate = time.Now()
}