Skip to content

Commit

Permalink
engine: Simplify code in mtask.cleanupTask
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelkarp committed Feb 10, 2017
1 parent 1db71f5 commit 1fdca9a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion agent/engine/dockerstate/docker_task_engine_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (state *DockerTaskEngineState) AddImageState(imageState *image.ImageState)
}

// RemoveTask removes a task from this state. It removes all containers and
// other associated metadata. It does aquire the write lock.
// other associated metadata. It does acquire the write lock.
func (state *DockerTaskEngineState) RemoveTask(task *api.Task) {
state.lock.Lock()
defer state.lock.Unlock()
Expand Down
10 changes: 3 additions & 7 deletions agent/engine/task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,12 @@ func (mtask *managedTask) cleanupTask(taskStoppedDuration time.Duration) {
// For the duration of this, simply discard any task events; this ensures the
// speedy processing of other events for other tasks
handleCleanupDone := make(chan struct{})
go func() {
mtask.engine.sweepTask(mtask.Task)
mtask.engine.state.RemoveTask(mtask.Task)
handleCleanupDone <- struct{}{}
}()
// discard events while the task is being removed from engine state
mtask.discardEventsUntil(handleCleanupDone)
go mtask.discardEventsUntil(handleCleanupDone)
mtask.engine.sweepTask(mtask.Task)
mtask.engine.state.RemoveTask(mtask.Task)
log.Debug("Finished removing task data; removing from state no longer managing", "task", mtask.Task)
// Now remove ourselves from the global state and cleanup channels
go mtask.discardEventsUntil(handleCleanupDone) // keep discarding events until the task is fully gone
mtask.engine.processTasks.Lock()
delete(mtask.engine.managedTasks, mtask.Arn)
handleCleanupDone <- struct{}{}
Expand Down

0 comments on commit 1fdca9a

Please sign in to comment.