Skip to content

Commit

Permalink
Merge pull request #3001 from hashicorp/f-template-events
Browse files Browse the repository at this point in the history
Template emits events explaining why it is blocked
  • Loading branch information
dadgar committed Aug 10, 2017
2 parents 6abd6d8 + 9cc5e19 commit a066856
Show file tree
Hide file tree
Showing 11 changed files with 810 additions and 426 deletions.
2 changes: 2 additions & 0 deletions api/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ const (
TaskRestartSignal = "Restart Signaled"
TaskLeaderDead = "Leader Task Dead"
TaskBuildingTaskDir = "Building Task Directory"
TaskGenericMessage = "Generic"
)

// TaskEvent is an event that effects the state of a task and contains meta-data
Expand Down Expand Up @@ -533,4 +534,5 @@ type TaskEvent struct {
VaultError string
TaskSignalReason string
TaskSignal string
GenericSource string
}
17 changes: 13 additions & 4 deletions client/alloc_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,10 @@ func (r *AllocRunner) setStatus(status, desc string) {
}
}

// setTaskState is used to set the status of a task. If state is empty then the
// event is appended but not synced with the server. The event may be omitted
func (r *AllocRunner) setTaskState(taskName, state string, event *structs.TaskEvent) {
// setTaskState is used to set the status of a task. If lazySync is set then the
// event is appended but not synced with the server. If state is omitted, the
// last known state is used.
func (r *AllocRunner) setTaskState(taskName, state string, event *structs.TaskEvent, lazySync bool) {
r.taskStatusLock.Lock()
defer r.taskStatusLock.Unlock()
taskState, ok := r.taskStates[taskName]
Expand All @@ -643,10 +644,18 @@ func (r *AllocRunner) setTaskState(taskName, state string, event *structs.TaskEv
r.appendTaskEvent(taskState, event)
}

if state == "" {
if lazySync {
return
}

// If the state hasn't been set use the existing state.
if state == "" {
state = taskState.State
if taskState.State == "" {
state = structs.TaskStatePending
}
}

switch state {
case structs.TaskStateRunning:
// Capture the start time if it is just starting
Expand Down
Loading

0 comments on commit a066856

Please sign in to comment.