Use client state

This commit is contained in:
Alex Dadgar 2015-12-16 14:34:17 -08:00
parent 7bec30c2b3
commit 561ccdb441

View file

@ -1489,18 +1489,19 @@ type Allocation struct {
// TerminalStatus returns if the desired or actual status is terminal and // TerminalStatus returns if the desired or actual status is terminal and
// will no longer transition. // will no longer transition.
func (a *Allocation) TerminalStatus() bool { func (a *Allocation) TerminalStatus() bool {
// First check the desired state and if that isn't terminal, check client
// state.
switch a.DesiredStatus { switch a.DesiredStatus {
case AllocDesiredStatusStop, AllocDesiredStatusEvict, AllocDesiredStatusFailed: case AllocDesiredStatusStop, AllocDesiredStatusEvict, AllocDesiredStatusFailed:
return true return true
default: default:
// If all tasks are dead, the alloc is terminal. }
for _, state := range a.TaskStates {
if state.State != TaskStateDead {
return false
}
}
switch a.ClientStatus {
case AllocClientStatusDead, AllocClientStatusFailed:
return true return true
default:
return false
} }
} }