Skip to content

Commit

Permalink
fix already stopped instance error
Browse files Browse the repository at this point in the history
  • Loading branch information
gamoutatsumi committed Apr 16, 2024
1 parent d9dd806 commit d29242f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pool-agent/cmd/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type Agent struct {
}
}

var (
ErrAlreadyStopped = errors.New("The instance is already stopped")
)

type instances map[string]struct{}

func newAgent(ctx context.Context, conf Config) (*Agent, error) {
Expand Down Expand Up @@ -272,10 +276,10 @@ func (a *Agent) deleteInstance(i api.Instance) error {
return fmt.Errorf("get instance %q: %w", i.Name, err)
}
stopOp, err := a.Client.UpdateInstanceState(i.Name, api.InstanceStatePut{Action: "stop", Timeout: -1, Force: true}, etag)
if err != nil {
if err != nil && !errors.Is(err, ErrAlreadyStopped) {
return fmt.Errorf("failed to stop instance %q: %+v", i.Name, err)
}
if err := stopOp.Wait(); err != nil {
if err := stopOp.Wait(); err != nil && !errors.Is(err, ErrAlreadyStopped) {
return fmt.Errorf("failed to stop instance %q: %+v", i.Name, err)
}
deleteOp, err := a.Client.DeleteInstance(i.Name)
Expand Down

0 comments on commit d29242f

Please sign in to comment.