Add TaskState to alloc
This commit is contained in:
parent
677b18ca52
commit
359251744f
|
@ -52,6 +52,7 @@ type Allocation struct {
|
|||
DesiredDescription string
|
||||
ClientStatus string
|
||||
ClientDescription string
|
||||
TaskStates map[string]*TaskState
|
||||
CreateIndex uint64
|
||||
ModifyIndex uint64
|
||||
}
|
||||
|
@ -83,6 +84,7 @@ type AllocationListStub struct {
|
|||
DesiredDescription string
|
||||
ClientStatus string
|
||||
ClientDescription string
|
||||
TaskStates map[string]*TaskState
|
||||
CreateIndex uint64
|
||||
ModifyIndex uint64
|
||||
}
|
||||
|
|
28
api/tasks.go
28
api/tasks.go
|
@ -110,3 +110,31 @@ func (t *Task) Constrain(c *Constraint) *Task {
|
|||
t.Constraints = append(t.Constraints, c)
|
||||
return t
|
||||
}
|
||||
|
||||
// TaskState tracks the current state of a task and events that caused state
|
||||
// transistions.
|
||||
type TaskState struct {
|
||||
State string
|
||||
Events []*TaskEvent
|
||||
}
|
||||
|
||||
// TaskEventType is the set of events that effect the state of a task.
|
||||
type TaskEventType int
|
||||
|
||||
const (
|
||||
TaskDriverFailure TaskEventType = iota
|
||||
TaskStarted
|
||||
TaskTerminated
|
||||
TaskKilled
|
||||
)
|
||||
|
||||
// TaskEvent is an event that effects the state of a task and contains meta-data
|
||||
// appropriate to the events type.
|
||||
type TaskEvent struct {
|
||||
Type TaskEventType
|
||||
Time int64
|
||||
DriverError error
|
||||
ExitCode int
|
||||
Signal int
|
||||
Message string
|
||||
}
|
||||
|
|
|
@ -1053,6 +1053,57 @@ func (t *Task) GoString() string {
|
|||
return fmt.Sprintf("*%#v", *t)
|
||||
}
|
||||
|
||||
// Set of possible states for a task.
|
||||
const (
|
||||
TaskStatePending = "pending" // The task is waiting to be run.
|
||||
TaskStateRunning = "running" // The task is currently running.
|
||||
TaskStateDead = "dead" // Terminal state of task.
|
||||
)
|
||||
|
||||
// TaskState tracks the current state of a task and events that caused state
|
||||
// transistions.
|
||||
type TaskState struct {
|
||||
// The current state of the task.
|
||||
State string
|
||||
|
||||
// Series of task events that transistion the state of the task.
|
||||
Events []*TaskEvent
|
||||
}
|
||||
|
||||
// TaskEventType is the set of events that effect the state of a task.
|
||||
type TaskEventType int
|
||||
|
||||
const (
|
||||
// A Driver failure indicates that the task could not be started due to a
|
||||
// failure in the driver.
|
||||
TaskDriverFailure TaskEventType = iota
|
||||
|
||||
// Task Started signals that the task was started and its timestamp can be
|
||||
// used to determine the running length of the task.
|
||||
TaskStarted
|
||||
|
||||
// Task terminated indicates that the task was started and exited.
|
||||
TaskTerminated
|
||||
|
||||
// Task Killed indicates a user has killed the task.
|
||||
TaskKilled
|
||||
)
|
||||
|
||||
// TaskEvent is an event that effects the state of a task and contains meta-data
|
||||
// appropriate to the events type.
|
||||
type TaskEvent struct {
|
||||
Type TaskEventType
|
||||
Time int64 // Unix Nanosecond timestamp
|
||||
|
||||
// Driver Failure fields.
|
||||
DriverError error // A driver error occured while starting the task.
|
||||
|
||||
// Task Terminated Fields.
|
||||
ExitCode int // The exit code of the task.
|
||||
Signal int // The signal that terminated the task.
|
||||
Message string // A possible message explaining the termination of the task.
|
||||
}
|
||||
|
||||
// Validate is used to sanity check a task group
|
||||
func (t *Task) Validate() error {
|
||||
var mErr multierror.Error
|
||||
|
@ -1171,6 +1222,9 @@ type Allocation struct {
|
|||
// ClientStatusDescription is meant to provide more human useful information
|
||||
ClientDescription string
|
||||
|
||||
// TaskStates stores the state of each task,
|
||||
TaskStates map[string]*TaskState
|
||||
|
||||
// Raft Indexes
|
||||
CreateIndex uint64
|
||||
ModifyIndex uint64
|
||||
|
@ -1200,6 +1254,7 @@ func (a *Allocation) Stub() *AllocListStub {
|
|||
DesiredDescription: a.DesiredDescription,
|
||||
ClientStatus: a.ClientStatus,
|
||||
ClientDescription: a.ClientDescription,
|
||||
TaskStates: a.TaskStates,
|
||||
CreateIndex: a.CreateIndex,
|
||||
ModifyIndex: a.ModifyIndex,
|
||||
}
|
||||
|
@ -1217,6 +1272,7 @@ type AllocListStub struct {
|
|||
DesiredDescription string
|
||||
ClientStatus string
|
||||
ClientDescription string
|
||||
TaskStates map[string]*TaskState
|
||||
CreateIndex uint64
|
||||
ModifyIndex uint64
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue