Skip to content

Commit

Permalink
Remove logic outside of handlescalingevent function
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun-m committed Dec 11, 2024
1 parent 17eace8 commit 3be4db5
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/abstractions/common/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,6 @@ func (i *AutoscaledInstance) HandleScalingEvent(desiredContainers int) error {
if len(state.FailedContainers) >= i.FailedContainerThreshold {
log.Printf("<%s> reached failed container threshold, scaling to zero.\n", i.Name)
desiredContainers = 0
go i.HandleDeploymentNotHealthy(i.Stub.ExternalId, types.StubStateDegraded, "failed container threshold", state.FailedContainers)
} else if len(state.FailedContainers) > 0 {
go i.HandleDeploymentNotHealthy(i.Stub.ExternalId, types.StubStateWarning, "one or more containers failed", state.FailedContainers)
} else if len(state.FailedContainers) == 0 {
go i.HandleDeploymentHealthy(i.Stub.ExternalId)
}

if !i.IsActive {
Expand All @@ -266,6 +261,8 @@ func (i *AutoscaledInstance) HandleScalingEvent(desiredContainers int) error {
err = i.StopContainersFunc(-containerDelta)
}

go i.handleUnhealthyDeploymentEvents(state.FailedContainers)

return err
}

Expand Down Expand Up @@ -296,7 +293,17 @@ func (i *AutoscaledInstance) State() (*AutoscaledInstanceState, error) {
return &state, nil
}

func (i *AutoscaledInstance) HandleDeploymentNotHealthy(stubId, currentState, reason string, containers []string) {
func (i *AutoscaledInstance) handleUnhealthyDeploymentEvents(failedContainers []string) {
if len(failedContainers) >= i.FailedContainerThreshold {
i.HandleDeploymentUnhealthy(i.Stub.ExternalId, types.StubStateDegraded, "failed container threshold", failedContainers)
} else if len(failedContainers) > 0 {
i.HandleDeploymentUnhealthy(i.Stub.ExternalId, types.StubStateWarning, "one or more containers failed", failedContainers)
} else if len(failedContainers) == 0 {
i.HandleDeploymentHealthy(i.Stub.ExternalId)
}
}

func (i *AutoscaledInstance) HandleDeploymentUnhealthy(stubId, currentState, reason string, containers []string) {
var state string
state, err := i.ContainerRepo.GetStubState(stubId)
if err != nil {
Expand Down

0 comments on commit 3be4db5

Please sign in to comment.