Correctly handle server responses and instantiation
This commit is contained in:
@@ -45,25 +45,27 @@ func LoadDirectory() error {
|
||||
log.WithField("total_configs", len(configs)).Info("processing servers returned by the API")
|
||||
|
||||
pool := workerpool.New(runtime.NumCPU())
|
||||
for uuid, data := range configs {
|
||||
uuid := uuid
|
||||
log.Debugf("using %d workerpools to instantiate server instances", runtime.NumCPU())
|
||||
for _, data := range configs {
|
||||
data := data
|
||||
|
||||
pool.Submit(func() {
|
||||
// Parse the json.RawMessage into an expected struct value. We do this here so that a single broken
|
||||
// server does not cause the entire boot process to hang, and allows us to show more useful error
|
||||
// messaging in the output.
|
||||
d := api.ServerConfigurationResponse{}
|
||||
d := api.ServerConfigurationResponse{
|
||||
Settings: data.Settings,
|
||||
}
|
||||
|
||||
log.WithField("server", uuid).Info("creating new server object from API response")
|
||||
if err := json.Unmarshal(data, &d); err != nil {
|
||||
log.WithField("server", uuid).WithField("error", err).Error("failed to parse server configuration from API response, skipping...")
|
||||
log.WithField("server", data.Uuid).Info("creating new server object from API response")
|
||||
if err := json.Unmarshal(data.ProcessConfiguration, &d.ProcessConfiguration); err != nil {
|
||||
log.WithField("server", data.Uuid).WithField("error", err).Error("failed to parse server configuration from API response, skipping...")
|
||||
return
|
||||
}
|
||||
|
||||
s, err := FromConfiguration(d)
|
||||
if err != nil {
|
||||
log.WithField("server", uuid).WithField("error", err).Error("failed to load server, skipping...")
|
||||
log.WithField("server", data.Uuid).WithField("error", err).Error("failed to load server, skipping...")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user