Skip to content

Commit

Permalink
Fix machine info fields (#193)
Browse files Browse the repository at this point in the history
Co-authored-by: Luke Lombardi <[email protected]>
  • Loading branch information
luke-lombardi and Luke Lombardi authored May 7, 2024
1 parent 7f13e3b commit 309831c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/repository/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ type TaskRepository interface {

type ProviderRepository interface {
GetMachine(providerName, poolName, machineId string) (*types.ProviderMachineState, error)
AddMachine(providerName, poolName, machineId string, info *types.ProviderMachineState) error
AddMachine(providerName, poolName, machineId string, machineInfo *types.ProviderMachineState) error
RemoveMachine(providerName, poolName, machineId string) error
RegisterMachine(providerName, poolName, machineId string, info *types.ProviderMachineState) error
RegisterMachine(providerName, poolName, machineId string, newMachineInfo *types.ProviderMachineState) error
WaitForMachineRegistration(providerName, poolName, machineId string) (*types.ProviderMachineState, error)
ListAllMachines(providerName, poolName string) ([]*types.ProviderMachine, error)
SetMachineLock(providerName, poolName, machineId string) error
Expand Down
22 changes: 14 additions & 8 deletions internal/repository/provider_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ func (r *ProviderRedisRepository) WaitForMachineRegistration(providerName, poolN
}
}

func (r *ProviderRedisRepository) AddMachine(providerName, poolName, machineId string, info *types.ProviderMachineState) error {
func (r *ProviderRedisRepository) AddMachine(providerName, poolName, machineId string, machineInfo *types.ProviderMachineState) error {
stateKey := common.RedisKeys.ProviderMachineState(providerName, poolName, machineId)

info.MachineId = machineId
info.Status = types.MachineStatusPending
machineInfo.MachineId = machineId
machineInfo.Status = types.MachineStatusPending

err := r.rdb.HSet(context.TODO(),
stateKey, common.ToSlice(info)).Err()
stateKey, common.ToSlice(machineInfo)).Err()

if err != nil {
return fmt.Errorf("failed to set machine state <%v>: %w", stateKey, err)
Expand Down Expand Up @@ -179,13 +179,19 @@ func (r *ProviderRedisRepository) RemoveMachine(providerName, poolName, machineI
return nil
}

func (r *ProviderRedisRepository) RegisterMachine(providerName, poolName, machineId string, info *types.ProviderMachineState) error {
func (r *ProviderRedisRepository) RegisterMachine(providerName, poolName, machineId string, newMachineInfo *types.ProviderMachineState) error {
stateKey := common.RedisKeys.ProviderMachineState(providerName, poolName, machineId)

info.MachineId = machineId
info.Status = types.MachineStatusRegistered
machineInfo, err := r.getMachineFromKey(stateKey)
if err != nil {
return fmt.Errorf("failed to get machine state <%v>: %w", stateKey, err)
}

machineInfo.HostName = newMachineInfo.HostName
machineInfo.Token = newMachineInfo.Token
machineInfo.Status = types.MachineStatusRegistered

err := r.rdb.HSet(context.TODO(), stateKey, common.ToSlice(info)).Err()
err = r.rdb.HSet(context.TODO(), stateKey, common.ToSlice(machineInfo)).Err()
if err != nil {
return fmt.Errorf("failed to set machine state <%v>: %w", stateKey, err)
}
Expand Down
1 change: 0 additions & 1 deletion internal/repository/worker_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ func (r *WorkerRedisRepository) ScheduleContainerRequest(worker *types.Worker, r
// Update the worker capacity first
err = r.UpdateWorkerCapacity(worker, request, types.RemoveCapacity)
if err != nil {
log.Println(err)
return err
}

Expand Down

0 comments on commit 309831c

Please sign in to comment.