Use DesiredState to determine whether to stop sending task events

This commit is contained in:
Preetha Appan
2019-01-22 16:43:32 -06:00
parent 678c6e834b
commit 26cb3cd12d
3 changed files with 9 additions and 5 deletions

View File

@@ -146,7 +146,7 @@ func (t *Tracker) TaskEvents() map[string]*structs.TaskEvent {
defer t.l.Unlock()
// Nothing to do since the failure wasn't task related
if t.allocFailed || t.alloc.TerminalStatus() {
if t.allocFailed {
return nil
}

View File

@@ -46,11 +46,11 @@ func (a *allocHealthSetter) SetHealth(healthy, isDeploy bool, trackerTaskEvents
a.ar.stateLock.Lock()
a.ar.state.SetDeploymentStatus(time.Now(), healthy)
a.ar.persistDeploymentStatus(a.ar.state.DeploymentStatus)
isTerminal := a.ar.alloc.TerminalStatus()
terminalDesiredState := a.ar.alloc.ServerTerminalStatus()
a.ar.stateLock.Unlock()
// If deployment is unhealthy emit task events explaining why
if !healthy && isDeploy && !isTerminal {
if !healthy && isDeploy && !terminalDesiredState {
for task, event := range trackerTaskEvents {
if tr, ok := a.ar.tasks[task]; ok {
// Append but don't emit event since the server

View File

@@ -7288,13 +7288,17 @@ func (a *Allocation) copyImpl(job bool) *Allocation {
func (a *Allocation) TerminalStatus() bool {
// First check the desired state and if that isn't terminal, check client
// state.
return a.ServerTerminalStatus() || a.ClientTerminalStatus()
}
// ServerTerminalStatus returns true if the desired state of the allocation is terminal
func (a *Allocation) ServerTerminalStatus() bool {
switch a.DesiredStatus {
case AllocDesiredStatusStop, AllocDesiredStatusEvict:
return true
default:
return false
}
return a.ClientTerminalStatus()
}
// ClientTerminalStatus returns if the client status is terminal and will no longer transition