no need to TaskStateUpdated to return an error

also updated comments
This commit is contained in:
Michael Schurter 2018-07-19 10:48:01 -07:00
parent fd3bc1bd39
commit a2bf851805
3 changed files with 7 additions and 15 deletions

View File

@ -233,14 +233,10 @@ func (ar *allocRunner) Restore() error {
})
}
// TaskStateUpdated is called when a task's state has been updated. This hook is
// used to compute changes to the alloc's ClientStatus and to update the server
// with the new state.
func (ar *allocRunner) TaskStateUpdated(taskName string, state *structs.TaskState) error {
if state == nil {
return fmt.Errorf("nil state given to TaskStateUpdated")
}
// TaskStateUpdated is called by TaskRunner when a task's state has been
// updated. This hook is used to compute changes to the alloc's ClientStatus
// and to update the server with the new state.
func (ar *allocRunner) TaskStateUpdated(taskName string, state *structs.TaskState) {
// If a task is dead, we potentially want to kill other tasks in the group
if state.State == structs.TaskStateDead {
// Find all tasks that are not the one that is dead and check if the one
@ -293,8 +289,6 @@ func (ar *allocRunner) TaskStateUpdated(taskName string, state *structs.TaskStat
if err := ar.stateUpdater.AllocStateUpdated(calloc); err != nil {
ar.logger.Error("failed to update remote allocation state", "error", err)
}
return nil
}
// clientAlloc takes in the task states and returns an Allocation populated

View File

@ -23,5 +23,5 @@ type AllocRunner interface {
// TaskStateHandler exposes a handler to be called when a task's state changes
type TaskStateHandler interface {
// TaskStateUpdated is used to emit updated task state
TaskStateUpdated(task string, state *structs.TaskState) error
TaskStateUpdated(task string, state *structs.TaskState)
}

View File

@ -519,10 +519,8 @@ func (tr *TaskRunner) SetState(state string, event *structs.TaskEvent) {
// Update the local state
stateCopy := tr.setStateLocal(state, event)
// Create a copy and notify the alloc runner of the transition
if err := tr.stateUpdater.TaskStateUpdated(tr.taskName, stateCopy); err != nil {
tr.logger.Error("failed to update remote state", "error", err)
}
// Notify the alloc runner of the transition
tr.stateUpdater.TaskStateUpdated(tr.taskName, stateCopy)
}
// setStateLocal updates the local in-memory state, persists a copy to disk and returns a