Code cleanup

This commit is contained in:
Dane Everitt 2020-07-19 17:09:38 -07:00
parent 0cbaad5c72
commit 16467fa7ff
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 13 additions and 6 deletions

View File

@ -80,7 +80,7 @@ func New(data []byte) (*Installer, error) {
// Create a new server instance using the configuration we wrote to the disk // Create a new server instance using the configuration we wrote to the disk
// so that everything gets instantiated correctly on the struct. // so that everything gets instantiated correctly on the struct.
s, err := server.FromConfiguration(c) s, err := server.FromConfiguration(c, true)
return &Installer{ return &Installer{
server: s, server: s,

View File

@ -43,18 +43,21 @@ func LoadDirectory() error {
return errors.New(rerr.String()) return errors.New(rerr.String())
} }
log.Debug("retrieving cached server states from disk")
states, err := getServerStates() states, err := getServerStates()
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
} }
log.WithField("total_configs", len(configs)).Debug("looping over received configurations from API")
for uuid, data := range configs { for uuid, data := range configs {
wg.Add() wg.Add()
go func(uuid string, data *api.ServerConfigurationResponse) { go func(uuid string, data *api.ServerConfigurationResponse) {
defer wg.Done() defer wg.Done()
s, err := FromConfiguration(data) log.WithField("uuid", uuid).Debug("creating server object from configuration")
s, err := FromConfiguration(data, false)
if err != nil { if err != nil {
log.WithField("server", uuid).WithField("error", err).Error("failed to load server, skipping...") log.WithField("server", uuid).WithField("error", err).Error("failed to load server, skipping...")
return return
@ -79,7 +82,7 @@ func LoadDirectory() error {
// Initializes a server using a data byte array. This will be marshaled into the // Initializes a server using a data byte array. This will be marshaled into the
// given struct using a YAML marshaler. This will also configure the given environment // given struct using a YAML marshaler. This will also configure the given environment
// for a server. // for a server.
func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) { func FromConfiguration(data *api.ServerConfigurationResponse, sync bool) (*Server, error) {
cfg := Configuration{} cfg := Configuration{}
if err := defaults.Set(&cfg); err != nil { if err := defaults.Set(&cfg); err != nil {
return nil, err return nil, err
@ -111,8 +114,10 @@ func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) {
} }
// Forces the configuration to be synced with the panel. // Forces the configuration to be synced with the panel.
if err := s.SyncWithConfiguration(data); err != nil { if sync {
return nil, err if err := s.SyncWithConfiguration(data); err != nil {
return nil, err
}
} }
return s, nil return s, nil

View File

@ -133,5 +133,7 @@ func (s *Server) GetState() string {
// environment state, it is simply the tracked state from this daemon instance, and // environment state, it is simply the tracked state from this daemon instance, and
// not the response from Docker. // not the response from Docker.
func (s *Server) IsRunning() bool { func (s *Server) IsRunning() bool {
return s.GetState() == ProcessRunningState || s.GetState() == ProcessStartingState st := s.GetState()
return st == ProcessRunningState || st == ProcessStartingState
} }