From 5366d0f6520765b658f89d90f161f78378bbeccb Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 31 Jul 2020 21:25:57 -0700 Subject: [PATCH] Use a workerpool for configuration file updates Co-Authored-By: Jakob --- server/config_parser.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/server/config_parser.go b/server/config_parser.go index 5b64099..06f46d5 100644 --- a/server/config_parser.go +++ b/server/config_parser.go @@ -1,34 +1,32 @@ package server import ( - "github.com/pterodactyl/wings/parser" - "sync" + "github.com/gammazero/workerpool" + "runtime" ) // Parent function that will update all of the defined configuration files for a server // automatically to ensure that they always use the specified values. func (s *Server) UpdateConfigurationFiles() { - wg := new(sync.WaitGroup) + pool := workerpool.New(runtime.GOMAXPROCS(0)) files := s.ProcessConfiguration().ConfigurationFiles - for _, v := range files { - wg.Add(1) + for _, cf := range files { + f := cf - go func(f parser.ConfigurationFile, server *Server) { - defer wg.Done() - - p, err := server.Filesystem.SafePath(f.FileName) + pool.Submit(func() { + p, err := s.Filesystem.SafePath(f.FileName) if err != nil { - server.Log().WithField("error", err).Error("failed to generate safe path for configuration file") + s.Log().WithField("error", err).Error("failed to generate safe path for configuration file") return } if err := f.Parse(p, false); err != nil { - server.Log().WithField("error", err).Error("failed to parse and update server configuration file") + s.Log().WithField("error", err).Error("failed to parse and update server configuration file") } - }(v, s) + }) } - wg.Wait() + pool.StopWait() } \ No newline at end of file