Skip to content

Commit

Permalink
Merge 8307a1d into cb410c1
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavosbarreto committed Jul 26, 2018
2 parents cb410c1 + 8307a1d commit cb8daa9
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions updatehub/updatehub.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ func (uh *UpdateHub) Cancel(nextState State) {
}

func (uh *UpdateHub) GetState() State {
uh.stateMutex.Lock()
defer uh.stateMutex.Unlock()

return uh.state
}

Expand Down Expand Up @@ -214,59 +217,53 @@ func (uh *UpdateHub) rollbackCallback() error {
}

func (uh *UpdateHub) ProcessCurrentState() State {
uh.stateMutex.Lock()
defer uh.stateMutex.Unlock()
state := uh.GetState()

var err error

es, isErrorState := uh.state.(*ErrorState)
es, isErrorState := state.(*ErrorState)
if isErrorState {
uh.ReportCurrentState()
// this must be done after the report, because the report uses it
uh.previousState = uh.state
uh.previousState = state

err = uh.errorCallback(es.cause.Error())
if err != nil {
log.Warn(err)
}

state, _ := uh.state.Handle(uh)
return state
s, _ := state.Handle(uh)
return s
}

flow, err := uh.stateChangeCallback(uh.state, "enter")
flow, err := uh.stateChangeCallback(state, "enter")

uh.ReportCurrentState()
// this must be done after the report, because the report uses it
uh.previousState = uh.state
uh.previousState = state

if err != nil {
log.Error(err)
return NewErrorState(uh.state.ApiClient(), nil, NewTransientError(err))
return NewErrorState(state.ApiClient(), nil, NewTransientError(err))
}

if flow != nil {
return flow
}

state, cancel := uh.state.Handle(uh)
s, _ := state.Handle(uh)

flow, err = uh.stateChangeCallback(uh.state, "leave")
flow, err = uh.stateChangeCallback(state, "leave")
if err != nil {
log.Error(err)
return NewErrorState(uh.state.ApiClient(), nil, NewTransientError(err))
return NewErrorState(state.ApiClient(), nil, NewTransientError(err))
}

if flow != nil {
return flow
}

cs, ok := state.(*CancellableState)
if cancel && ok {
return cs.NextState()
}

return state
return s
}

type Controller interface {
Expand Down

0 comments on commit cb8daa9

Please sign in to comment.