Fix the capacity

This commit is contained in:
Alex Dadgar
2015-11-16 12:10:29 -08:00
parent fa68fb62d3
commit b692bcd0b4
3 changed files with 19 additions and 12 deletions

View File

@@ -130,7 +130,7 @@ const (
type TaskEvent struct {
Type string
Time int64
DriverError error
DriverError string
ExitCode int
Signal int
Message string

View File

@@ -183,16 +183,6 @@ func (r *AllocRunner) Alloc() *structs.Allocation {
return r.alloc
}
// setAlloc is used to update the allocation of the runner
// we preserve the existing client status and description
func (r *AllocRunner) setAlloc(alloc *structs.Allocation) {
if r.alloc != nil {
alloc.ClientStatus = r.alloc.ClientStatus
alloc.ClientDescription = r.alloc.ClientDescription
}
r.alloc = alloc
}
// dirtySyncState is used to watch for state being marked dirty to sync
func (r *AllocRunner) dirtySyncState() {
for {

View File

@@ -137,11 +137,27 @@ func (r *TaskRunner) DestroyState() error {
return os.RemoveAll(r.stateFilePath())
}
func (r *TaskRunner) appendEvent(event *structs.TaskEvent) {
capacity := 10
if r.state.Events == nil {
r.state.Events = make([]*structs.TaskEvent, 0, capacity)
}
// If we hit capacity, then shift it.
if len(r.state.Events) == capacity {
old := r.state.Events
r.state.Events = make([]*structs.TaskEvent, 0, capacity)
r.state.Events = append(r.state.Events, old[1:]...)
}
r.state.Events = append(r.state.Events, event)
}
// setState is used to update the state of the task runner
func (r *TaskRunner) setState(state string, event *structs.TaskEvent) {
// Update the task.
r.state.State = state
r.state.Events = append(r.state.Events, event)
r.appendEvent(event)
// Persist our state to disk.
if err := r.SaveState(); err != nil {
@@ -278,6 +294,7 @@ OUTER:
// Recurse on ourselves and force the start since we are restarting the task.
r.run(true)
// TODO: Alex
return
}