Cleanup logic for updating stats to avoid calling mutex outside of file

This commit is contained in:
Dane Everitt 2022-01-30 11:55:59 -05:00
parent d7c7155802
commit 57daf0889a
2 changed files with 10 additions and 6 deletions

View File

@ -122,13 +122,10 @@ func (s *Server) StartEventListeners() {
}()
case e := <-stats:
go func() {
// Update the server resource tracking object with the resources we got here.
s.resources.mu.Lock()
s.resources.Stats = e.Data.(environment.Stats)
s.resources.mu.Unlock()
s.resources.UpdateStats(e.Data.(environment.Stats))
// If there is no disk space available at this point, trigger the server disk limiter logic
// which will start to stop the running instance.
// If there is no disk space available at this point, trigger the server
// disk limiter logic which will start to stop the running instance.
if !s.Filesystem().HasSpaceAvailable(true) {
l.Trigger()
}

View File

@ -38,6 +38,13 @@ func (s *Server) Proc() ResourceUsage {
return s.resources
}
// UpdateStats updates the current stats for the server's resource usage.
func (ru *ResourceUsage) UpdateStats(stats environment.Stats) {
ru.mu.Lock()
ru.Stats = stats
ru.mu.Unlock()
}
// Reset resets the usages values to zero, used when a server is stopped to ensure we don't hold
// onto any values incorrectly.
func (ru *ResourceUsage) Reset() {