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

View File

@ -38,6 +38,13 @@ func (s *Server) Proc() ResourceUsage {
return s.resources 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 // Reset resets the usages values to zero, used when a server is stopped to ensure we don't hold
// onto any values incorrectly. // onto any values incorrectly.
func (ru *ResourceUsage) Reset() { func (ru *ResourceUsage) Reset() {