Skip to content

Commit

Permalink
Add naming changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun-m committed Dec 11, 2024
1 parent 847ca18 commit 17eace8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
13 changes: 5 additions & 8 deletions pkg/abstractions/common/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,35 +298,32 @@ func (i *AutoscaledInstance) State() (*AutoscaledInstanceState, error) {

func (i *AutoscaledInstance) HandleDeploymentNotHealthy(stubId, currentState, reason string, containers []string) {
var state string
state, err := i.ContainerRepo.GetStubUnhealthyState(stubId)
state, err := i.ContainerRepo.GetStubState(stubId)
if err != nil {
log.Printf("<%s> failed to get unhealthy state\n", i.Name)
return
}

if state == currentState {
return
}

err = i.ContainerRepo.SetStubUnhealthyState(stubId, currentState)
err = i.ContainerRepo.SetStubState(stubId, currentState)
if err != nil {
log.Printf("<%s> failed to set unhealthy state\n", i.Name)
return
}

go i.EventRepo.PushStubStateNotHealthy(i.Workspace.ExternalId, stubId, currentState, state, reason, containers)
go i.EventRepo.PushStubStateUnhealthy(i.Workspace.ExternalId, stubId, currentState, state, reason, containers)
}

func (i *AutoscaledInstance) HandleDeploymentHealthy(stubId string) {
var state string
state, err := i.ContainerRepo.GetStubUnhealthyState(stubId)
state, err := i.ContainerRepo.GetStubState(stubId)
if err != nil || state == types.StubStateHealthy {
return
}

err = i.ContainerRepo.DeleteStubUnhealthyState(stubId)
err = i.ContainerRepo.DeleteStubState(stubId)
if err != nil {
log.Printf("<%s> failed to set unhealthy state\n", i.Name)
return
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/common/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
schedulerContainerLock string = "scheduler:container:lock:%s"
schedulerContainerExitCode string = "scheduler:container:exit_code:%s"
schedulerCheckpointState string = "scheduler:checkpoint_state:%s:%s"
schedulerStubUnhealthyState string = "scheduler:stub:unhealthy_state:%s"
schedulerStubState string = "scheduler:stub:state:%s"
)

var (
Expand Down Expand Up @@ -147,8 +147,8 @@ func (rk *redisKeys) SchedulerCheckpointState(workspaceName, checkpointId string
return fmt.Sprintf(schedulerCheckpointState, workspaceName, checkpointId)
}

func (rk *redisKeys) SchedulerStubUnhealthyState(stubId string) string {
return fmt.Sprintf(schedulerStubUnhealthyState, stubId)
func (rk *redisKeys) SchedulerStubState(stubId string) string {
return fmt.Sprintf(schedulerStubState, stubId)
}

// Gateway keys
Expand Down
8 changes: 4 additions & 4 deletions pkg/repository/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ type ContainerRepository interface {
GetFailedContainersByStubId(stubId string) ([]string, error)
UpdateCheckpointState(workspaceName, checkpointId string, checkpointState *types.CheckpointState) error
GetCheckpointState(workspaceName, checkpointId string) (*types.CheckpointState, error)
GetStubUnhealthyState(stubId string) (string, error)
SetStubUnhealthyState(stubId, state string) error
DeleteStubUnhealthyState(stubId string) error
GetStubState(stubId string) (string, error)
SetStubState(stubId, state string) error
DeleteStubState(stubId string) error
}

type WorkspaceRepository interface {
Expand Down Expand Up @@ -183,7 +183,7 @@ type EventRepository interface {
PushRunStubEvent(workspaceId string, stub *types.Stub)
PushTaskUpdatedEvent(task *types.TaskWithRelated)
PushTaskCreatedEvent(task *types.TaskWithRelated)
PushStubStateNotHealthy(workspaceId string, stubId string, currentState, previousState string, reason string, failedContainers []string)
PushStubStateUnhealthy(workspaceId string, stubId string, currentState, previousState string, reason string, failedContainers []string)
PushStubStateHealthy(workspaceId string, stubId string, previousState string)
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/repository/container_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ func (cr *ContainerRedisRepository) GetCheckpointState(workspaceName, checkpoint
return state, nil
}

func (cr *ContainerRedisRepository) GetStubUnhealthyState(stubId string) (string, error) {
stateKey := common.RedisKeys.SchedulerStubUnhealthyState(stubId)
func (cr *ContainerRedisRepository) GetStubState(stubId string) (string, error) {
stateKey := common.RedisKeys.SchedulerStubState(stubId)
state, err := cr.rdb.Get(context.TODO(), stateKey).Result()
if err != nil {
if err == redis.Nil {
Expand All @@ -472,12 +472,12 @@ func (cr *ContainerRedisRepository) GetStubUnhealthyState(stubId string) (string

var unhealthyStateTTL = 10 * time.Minute

func (cr *ContainerRedisRepository) SetStubUnhealthyState(stubId, state string) error {
stateKey := common.RedisKeys.SchedulerStubUnhealthyState(stubId)
func (cr *ContainerRedisRepository) SetStubState(stubId, state string) error {
stateKey := common.RedisKeys.SchedulerStubState(stubId)
return cr.rdb.SetEx(context.TODO(), stateKey, state, unhealthyStateTTL).Err()
}

func (cr *ContainerRedisRepository) DeleteStubUnhealthyState(stubId string) error {
stateKey := common.RedisKeys.SchedulerStubUnhealthyState(stubId)
func (cr *ContainerRedisRepository) DeleteStubState(stubId string) error {
stateKey := common.RedisKeys.SchedulerStubState(stubId)
return cr.rdb.Del(context.TODO(), stateKey).Err()
}
2 changes: 1 addition & 1 deletion pkg/repository/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (t *TCPEventClientRepo) PushTaskCreatedEvent(task *types.TaskWithRelated) {
)
}

func (t *TCPEventClientRepo) PushStubStateNotHealthy(workspaceId string, stubId string, currentState string, previousState string, reason string, failedContainers []string) {
func (t *TCPEventClientRepo) PushStubStateUnhealthy(workspaceId string, stubId string, currentState string, previousState string, reason string, failedContainers []string) {
t.pushEvent(
fmt.Sprintf("stub.state.%s", strings.ToLower(currentState)),
types.EventStubStateSchemaVersion,
Expand Down

0 comments on commit 17eace8

Please sign in to comment.