rework where time gets set

This commit is contained in:
Alex Dadgar
2018-04-10 12:49:59 -07:00
committed by Preetha Appan
parent 1050b89ac3
commit 2d6264e75d
2 changed files with 6 additions and 4 deletions

View File

@@ -50,7 +50,8 @@ type AllocRunner struct {
alloc *structs.Allocation
allocClientStatus string // Explicit status of allocation. Set when there are failures
allocClientDescription string
allocHealth *bool // Whether the allocation is healthy
allocHealth *bool // Whether the allocation is healthy
allocHealthTime time.Time // Time at which allocation health has been set
allocBroadcast *cstructs.AllocBroadcaster
allocLock sync.Mutex
@@ -577,11 +578,10 @@ func (r *AllocRunner) Alloc() *structs.Allocation {
// The health has been set
if r.allocHealth != nil {
if alloc.DeploymentStatus == nil {
alloc.DeploymentStatus = &structs.AllocDeploymentStatus{
Timestamp: time.Now(),
}
alloc.DeploymentStatus = &structs.AllocDeploymentStatus{}
}
alloc.DeploymentStatus.Healthy = helper.BoolToPtr(*r.allocHealth)
alloc.DeploymentStatus.Timestamp = r.allocHealthTime
}
r.allocLock.Unlock()
@@ -945,6 +945,7 @@ OUTER:
// If the deployment ids have changed clear the health
if r.alloc.DeploymentID != update.DeploymentID {
r.allocHealth = nil
r.allocHealthTime = time.Time{}
}
r.alloc = update

View File

@@ -112,6 +112,7 @@ func (r *AllocRunner) watchHealth(ctx context.Context) {
r.allocLock.Lock()
r.allocHealth = helper.BoolToPtr(allocHealthy)
r.allocHealthTime = time.Now()
r.allocLock.Unlock()
// If deployment is unhealthy emit task events explaining why