Skip to content

Commit

Permalink
fix(sessions): return and heanlde error everytime
Browse files Browse the repository at this point in the history
  • Loading branch information
acouvreur committed Jul 10, 2024
1 parent 3a74b3f commit 5013836
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions app/sessions/sessions_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sessions
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"sync"
Expand Down Expand Up @@ -178,36 +179,36 @@ func (s *SessionsManager) RequestSessionGroup(group string, duration time.Durati
}

func (s *SessionsManager) requestSessionInstance(name string, duration time.Duration) (*instance.State, error) {
if name == "" {
return nil, errors.New("instance name cannot be empty")
}

requestState, exists := s.store.Get(name)

if !exists {
log.Debugf("starting %s...", name)
log.Debugf("starting [%s]...", name)

err := s.provider.Start(s.ctx, name)
if err != nil {
errState, _ := instance.ErrorInstanceState(name, err, 1)
requestState.Name = errState.Name
requestState.CurrentReplicas = errState.CurrentReplicas
requestState.DesiredReplicas = errState.DesiredReplicas
requestState.Status = errState.Status
requestState.Message = errState.Message
} else {
state, _ := s.provider.GetState(s.ctx, name)
requestState.CurrentReplicas = state.CurrentReplicas
requestState.DesiredReplicas = state.DesiredReplicas
requestState.Status = state.Status
requestState.Message = state.Message
return nil, err
}

log.Debugf("status for %s=%s", name, requestState.Status)
} else if requestState.Status != instance.Ready {
log.Debugf("checking %s...", name)

state, err := s.provider.GetState(s.ctx, name)
if err != nil {
return nil, err
}

requestState.CurrentReplicas = state.CurrentReplicas
requestState.DesiredReplicas = state.DesiredReplicas
requestState.Status = state.Status
requestState.Message = state.Message

log.Debugf("status for [%s]=[%s]", name, requestState.Status)
} else if requestState.Status != instance.Ready {
log.Debugf("checking [%s]...", name)
state, err := s.provider.GetState(s.ctx, name)
if err != nil {
log.Errorf("an error occurred checking state %s: %s", name, err.Error())
return nil, err
}

requestState.Name = state.Name
Expand Down

0 comments on commit 5013836

Please sign in to comment.